Menu Samaritan's Purse

ARRAY_RAND

Pick one or more random keys out of an array

SYNTAX

array_rand ( array $array [, int $num = 1 ] ) : mixed

PARAMETERS

array

The input array.

num

Specifies how many entries should be picked.

RETURN

When picking only one entry, array_rand() 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.

EXAMPLES

ARRAY

2

NUM

Array
(
    [0] => 0
    [1] => 1
)

RETURN

Peter
John

PHP