Rearrange the elements in the array in random order:
<?php$my_array = array("red","green","blue","yellow","purple");shuffle($my_array);print_r($my_array);?>The shuffle() function rearranges the elements in the array in random order.
This function assigns new keys to elements in the array and existing keys are deleted (see Example 1 below).
shuffle( array )
parameter | describe |
---|---|
array | Required. Specifies the array to use. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 4+ |
Update log: | As of PHP 4.2.0, the random number generator is automatically seeded. |
Rearrange the elements in the array in random order:
<?php$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>" purple");shuffle($my_array);print_r($my_array);?>