array_rand
mixed array_rand(array array, [int num_elements])
array | Array from which to pick random elements |
num_elements | Number of elements to pick at random |
Returns one or more keys at random from an array.
Returns:
Key or array of keys of random elements of an array; NULL on failure
Description:
This function selects num_elements elements at random from the array given by array and returns their keys as elements in a new array. If num_elements is 1 or omitted, a single key is returned. Otherwise, an indexed array is returned; the selected keys are the element values in the returned array.
Since array_rand() internally uses the rand() function, you should use srand() before calling array_rand() to ensure the greatest possible randomness. ...
Get PHP Functions Essential Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.