Name

array_rand

Synopsis

mixed array_rand(array array[, int count])

Picks a random element from the given array. The second, optional, parameter can be given to specify a number of elements to pick and return. If more than one element is returned, an array of keys is returned, rather than the element’s value.

Before you call array_rand( ), be sure to seed the random-number generator using srand( ).

Get Programming PHP, 2nd Edition 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.