PHP array_rand() Function

PHP array_rand Function


Definition:

The array_rand() function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.

Syntax :

    array_rand(array, number)

Parameter :
Parameter Description
array Required. Specifies an array
number Optional. Specifies how many random keys to return

Example1 : Given below example return random output  array of key

Output : when we refresh output will change randomly

Web
Online
Promotion

Example2 : Return a random key from an array

Output : c (when we refresh output will change)