扫码一下
查看教程更方便
shuffle()
函数把数组中的元素按随机顺序重新排列:
<?php
$my_array = array("red","green","blue","yellow","purple");
shuffle($my_array);
print_r($my_array);
?>
执行结果
Array ( [0] => blue [1] => green [2] => yellow [3] => red [4] => purple )
Refresh the page to see how shuffle() randomizes the order of the elements in the array.
shuffle()
函数把数组中的元素按随机顺序重新排列。
该函数为数组中的元素分配新的键名,已存在的键名将被删除(参见下面的实例 1)。
shuffle(array)
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
#1 把数组中的元素按随机顺序重新排列:
<?php
$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");
shuffle($my_array);
print_r($my_array);
?>
执行结果
Array ( [0] => red [1] => blue [2] => green [3] => purple [4] => yellow )
Refresh the page to see how shuffle() randomizes the order of the elements in the array.