将MYSQL数据按要求取出后存放在一个数组中(基本是二维的)
<?php
srand((float) microtime() * 10000000);
//这里的array应为你从数据库内提出的数据
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank","sports98","asdf");
//DUB print_r($input);
$rand_key=array_rand($input, count($input));
//如果大数量的话,建议不要再转入数组,而是直接利用$rand_key获得随机后的记录位置
for($Tmpa=0;$Tmpa<count($rand_key);$Tmpa++){
$NewInput[$Tmpa]=$input[$rand_key[$Tmpa]];
}
//DUB print_r($NewInput);
?>
<?php
srand((float) microtime() * 10000000);
//这里的array应为你从数据库内提出的数据
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank","sports98","asdf");
//DUB print_r($input);
$rand_key=array_rand($input, count($input));
//如果大数量的话,建议不要再转入数组,而是直接利用$rand_key获得随机后的记录位置
for($Tmpa=0;$Tmpa<count($rand_key);$Tmpa++){
$NewInput[$Tmpa]=$input[$rand_key[$Tmpa]];
}
//DUB print_r($NewInput);
?>
(PHP 3>= 3.0.8, PHP 4 )shuffle -- 将数组打乱
说明
void shuffle ( array array)
本函数打乱(随机排列单元的顺序)一个数组。必须用 srand() 播下本函数的随机数发生器种子。
例子 1. shuffle() 例子<?php
$numbers = range (1,20);
srand ((float)microtime()*1000000);
shuffle ($numbers);
while (list (, $number) = each ($numbers)) {
echo "$number ";
}
?>
注: 在 PHP 4.2.0 中,无需用函数 srand() 或 mt_srand()来搜寻随机数生成器,它将被自动完成。 参见 arsort(),asort(),ksort(),rsort(),sort() 和 usort()。手册中是这样写的,实际应用中也是可行的,呵呵...