Home > php教程 > php手册 > body text

php使用array_rand()函数从数组中随机选择一个或多个元素

WBOY
Release: 2016-06-06 20:23:03
Original
1103 people have browsed it

这篇文章主要介绍了php使用array_rand()函数从数组中随机选择一个或多个元素,需要的朋友可以参考下

使用array_rand() 函数从数组中随机选出一个或多个元素,,并返回。

复制代码 代码如下:


array_rand(array,number)


参数 描述

array 必需。规定输入的数组参数。

number 可选。默认是 1。规定返回多少个随机的元素。

例子:

复制代码 代码如下:


$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r(array_rand($a,1));
?>


结果:

b
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template