PHP » Arrays » shuffle()

Syntax:
void shuffle(array array)
array
Array to be shuffled.

Reorders an array randomly.

shuffle() orders the elements in an array randomly. In versions prior to PHP 4.2.0, the randomizer should be seeded.

Examples

Code:
<?php

$array1 = range(1, 9);

shuffle($array1);
foreach ($array1 as $element) {
   print "$element ";
}

?>
Output:
7 3 1 6 8 5 4 9 2
Explanation:

The digits 1 through 9 are randomly reordered.

See Also: