Query: array_rand
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
ARRAY_RAND(3) 1 ARRAY_RAND(3) array_rand - Pick one or more random entries out of an arraySYNOPSISmixed array_rand (array $array, [int $num = 1])DESCRIPTIONPicks one or more random entries out of an array, and returns the key (or keys) of the random entries.PARAMETERSo $array - The input array. o $num - Specifies how many entries should be picked.RETURN VALUESWhen picking only one entry, array_rand(3) returns the key for a random entry. Otherwise, an array of keys for the random entries is returned. This is done so that random keys can be picked from the array as well as random values. Trying to pick more elements than there are in the array will result in an E_WARNING level error, and NULL will be returned.CHANGELOG+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | The resulting array of keys is no longer shuf- | | | fled. | | | | +--------+---------------------------------------------------+EXAMPLESExample #1 array_rand(3) example <?php $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . " "; echo $input[$rand_keys[1]] . " "; ?>SEE ALSOshuffle(3). PHP Documentation Group ARRAY_RAND(3)
Related Man Pages |
---|
array_count_values(3) - php |
array_flip(3) - php |
array_keys(3) - php |
array_combine(3) - php |
array_unshift(3) - php |
Similar Topics in the Unix Linux Community |
---|
Lets give Neo a hand. |
What is Linux? |
space not allowed in input |
randomly shuffle two text files the same way |
Failure using regex with awk in 'while read file' loop |