Home  >  Article  >  Backend Development  >  php-Arrays function-array_rand-randomly remove one or more cells from an array_PHP tutorial

php-Arrays function-array_rand-randomly remove one or more cells from an array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:041202browse

array_rand() randomly removes one or more cells from the array

【Function】
This function will return the specified number of array elements in an array.
                                                             This function will return the key name of a random unit, otherwise it will return an array containing random key names
This way you can randomly extract key names and values ​​from the array
【Scope of use】
​​​​​ php4, php5.
【Use】
​​​​​ mixed array_rand( array input[.int num_req] )
The return value is a mixed type, and the parameter input is the original array to be retrieved
The optional parameter num_req is the number of elements to be taken out
【Example】
[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)
}
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478220.htmlTechArticlearray_rand() Randomly remove one or more units from the array [Function] This function will return an array Specifies the number of array elements. If only one is taken out, this function will return one...
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