Randomize the order of the elements in the array:
<?php
$my_array = array("red","green","blue","yellow","purple");
shuffle($my_array);
print_r($my_array);
?>
Try it Yourself »
The shuffle() function randomizes the order of the elements in the array.
This function assigns new keys for the elements in the array. Existing keys will be removed (See Example below).
shuffle(
array)
Parameter | Description |
---|---|
array | Required. Specifies the array to use |
Return Value: | Returns TRUE on success or FALSE on failure |
---|---|
PHP Version: | 4+ |
PHP Changelog: | PHP 4.2: The random number generator is seeded automatically |
Randomize the order of the elements in the array:
<?php
$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");
shuffle($my_array);
print_r($my_array);
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!