PHP 怎么随机获取数组里面的值

 

注意array_rand随机返回的是KEY值的集合

<?php
srand((float) microtime() * 10000000);
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
print $input[$rand_keys[0]] . "\n";
print $input[$rand_keys[1]] . "\n";
?>

 

posted @ 2015-08-18 15:26  谦信君  阅读(4544)  评论(0编辑  收藏  举报