使用array_rand() 函数从数组中随机选出一个或多个元素,并返回。
array_rand(array,number)
参数 描述
array 必需。规定输入的数组参数。
number 可选。默认是 1。规定返回多少个随机的元素。
例子:
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r(array_rand($a,1));
?>
结果:
b
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn