Array_rand () is used to randomly extract one or more units from an array. it is quite useful to retrieve one or more random units from an array, it accepts input as an input array and an optional parameter num_req, specifying you... array_rand () is used to randomly extract one or more units from an array. it is quite useful to retrieve one or more random units from an array, it accepts input as an input array and an optional parameter num_req, specifying the number of units you want to retrieve-if not specified, the default value is 1. if you only retrieve one, array_rand () returns the key name of a random unit. Otherwise, an array containing the random key name is returned.
Array_rand () definition and usage
The array_rand () function randomly selects one or more elements from the array and returns the result. the second parameter is used to determine the elements to be selected. if more than one element is selected, an array containing a random key name is returned. Otherwise, the key name of the element is returned.
Note:From php 4.2.0, the random number generator is no longer needed to be planted using the srand () or mt_srand () function, which has been automatically completed.
Syntax:Array_rand (array, number)
Parameter description
Array required, specifying the input array parameters.
Number (optional) the default value is 1, which specifies the number of random elements returned.
The PHP instance code is as follows:
"dog","b"=>"cat","c"=>"horse"); print_r(array_rand($a,1));
Permanent link:
Reprint at will! Include the article address.