We can randomly collect one or more element from an array by using array_rand() function in PHP. We can specify the number of random elements required by specifying an optional parameter in side the function.
|
1 2 3 4 5 |
$value= array("Rabin","Reid","Cris","KVJ","John"); $rand_keys=array_rand($value,2); echo "First random element = ".$value[$rand_keys[0]]; echo "<br>Second random element = ".$value[$rand_keys[1]]; |
Tagged with: PHP
Filed under: PHP
Like this post? Subscribe to my RSS feed and get loads more!




Leave a Reply