Rearrange the elements in the array in a random order.
<?php $my_array = array(“red”,“green”,“blue”,“yellow”,“purple”); shuffle($my_array); print_r($my_array); ?> |
The shuffle() function randomizes the order of elements in the array.
This function assigns new keys to the elements, removing any existing keys (see example below).
shuffle(array) |
Parameter |
Description |
array |
Required. Specifies the array to be used. |
Return Value: |
Returns TRUE on success or FALSE on failure. |
PHP Version: |
4+ |
PHP Changelog: |
PHP 4.2: The random number generator is automatically seeded. |
Shuffle the elements in the array into a random order.
<?php $my_array = array(“a”=>“red”,“b”=>“green”,“c”=>“blue”,“d”=>“yellow”,“e”=>“purple”); shuffle($my_array); print_r($my_array); ?> |