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