Getting Random Elements from an Array in PHP


Fetch a random element from an array with array_rand().

Source Code

$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$randKey = array_rand($input);
echo $input[$randKey];
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments