submitted by:

PHP: Return random array element

Return a random array element using the array_rand() function.


code snippet:
<?php
$colors 
= array('red','orange','yellow','green','blue');
echo 
$colors[array_rand($colors)];
?>

sample output:
blue

notes:
Obviously your output will be random :) Please note: the array_rand() function returns a random key, so it can be used for indexed or associative arrays.