数组 函数
PHP 手册

shuffle

(PHP 4, PHP 5)

shuffle将数组打乱

说明

bool shuffle ( array &$array )

本函数打乱(随机排列单元的顺序)一个数组。

Note: 本函数为 array 中的单元赋予新的键名。这将删除原有的键名而不仅是重新排序。

Example #1 shuffle() 例子

<?php
$numbers 
range(1,20);
srand((float)microtime()*1000000);
shuffle($numbers);
foreach (
$numbers as $number) {
    echo 
"$number ";
}
?>

Note: 自 PHP 4.2.0 起,不再需要用 srand()mt_srand() 函数给随机数发生器播种,现已自动完成。

参见 arsort()asort()ksort()rsort()sort()usort()


数组 函数
PHP 手册