Php - How to pick random element from array, Function array_rand
How to pick random element from array
array_rand => Pick one or more random entries out of an array
This function can be used to fetch one or more elements from an array in php.
Example:
<?php $a = array(1,2,3,4,5); $result = array_rand($a); echo $result; ?>
This will chose a random number from the array $a.
To chose more than one random element from array we have to pass a second argument.
Example:
<?php $a = array(1,2,3,4,5); $result = array_rand($a,2); echo $result; ?>
This returns two random elements.
The topic on Php - How to pick random element from array is posted by - Mallu
Hope you have enjoyed, Php - How to pick random element from arrayThanks for your time