$items = Array(523,3452,334,31,...5346);
该数组中的每一项都是某个数字。
如何从 $items
**?**获取随机项目
发布于 2010-11-20 23:17:25
echo $items[array_rand($items)];
发布于 2010-11-20 23:18:04
如果您不介意在其他时间再次选择相同的项目:
$items[rand(0, count($items) - 1)];
发布于 2013-12-23 18:54:19
使用PHP随机函数
<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>
https://stackoverflow.com/questions/4233407
复制相似问题