array_rand() function in php
- Thursday, July 22, 2010, 9:15
- PHP
- Add a comment
|
|
Using array_rand() function we can collect one or more elements from an array in php Otherwise, it returns an array of keys for the random entries.
{code codetype=php}
<?php
$array= array(“syam”,”ammu”,”kichu”,”david”,”John”,”abhi”);
$rand_fun=array_rand($array,2);
echo “First random element = “.$array[$rand_fun[0]];
echo “<br>Second random element = “.$array[$rand_fun[1]];
?>
{/code}


