Heim  >  Artikel  >  Backend-Entwicklung  >  php-Arrays函数-array_rand-从数组中随机取出一个或多个单元_PHP教程

php-Arrays函数-array_rand-从数组中随机取出一个或多个单元_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:51:041203Durchsuche

array_rand() 从数组中随机取出一个或多个单元

【功能】
         该函数将返回一个数组中的指定个数的数组元素。
         如果只取出一个该函数将返回一个随机单元的键名,否则就返回一个包含随机键名的数组
         这样就可以随机从数组中随机取出键名和值   
【使用范围】
         php4、php5.
【使用】
         mixed array_rand( array input[.int num_req] )
         返回值为混合型,参数input为即将进行取出操作的原始数组
         可选参数num_req为即将取出的元素个数
【示例】
[php]
srand((float)microtime()*10000000); 
$input=array("Neo","Morpheus","Trinity","Cypher","Than"); 
var_dump(array_rand($input,2)); 
/*
array(2) {
  [0]=>
  int(0)
  [1]=>
  int(4)
}
*/ 

 


摘自 zuodefeng的笔记

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478220.htmlTechArticlearray_rand() 从数组中随机取出一个或多个单元 【功能】 该函数将返回一个数组中的指定个数的数组元素。 如果只取出一个该函数将返回一个...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn