array_rand
array_rand
Pick one or more random keys out of an array
**array_rand** array $array int $num
Picks one or more random entries out of an array, and returns the key (or keys) of the random entries.
arrayThe input array.
Cannot be empty.
num
Specifies how many entries should be picked.
Must be greater than zero, and less than or equal to the length of
array
When picking only one entry, 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. If multiple keys are returned,
they will be returned in the order they were present in the original array.
array_rand
Throws a if is empty,
or if is out of range.
ValueError``array``num
Voorbeeld: example
<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>
Random\Randomizer::pickArrayKeys``Random\Randomizer::shuffleArray