PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How can I mix up the order of values in an array?


A simple way to achieve the result of mixing up the values in an array is to use the shuffle function, which takes the name of the array you want to randomise. Here is a code snippet to demonstrate the shuffle function in action:

<?php
$values 
range("A","Z");
shuffle($values);
print_r($values);
?>


This will print something like the below, shuffling up the letters of the alphabet:

Array
(
[0] => J
[1] => R
[2] => C
[3] => W
[4] => Y
[5] => L
[6] => B
[7] => A
[8] => P
[9] => O
[10] => M
[11] => V
[12] => D
[13] => X
[14] => F
[15] => S
[16] => Q
[17] => G
[18] => I
[19] => H
[20] => N
[21] => Z
[22] => U
[23] => E
[24] => K
[25] => T
)



ASK A QUESTION

More arrays PHP Questions

I am not interested in the values in the arrays, how can I discard them?

How do I write my own sort function?

How do I check if a variable is of array type?

Translation Composition Nationalism European Grammar Arabic Poetry Prose ******************************* I want an array equation that helps me to calculate some of varibles unspecific

How do I sort alphanumeric array data correctly?



Custom Search