Jaswinder Posted August 11, 2013 Share Posted August 11, 2013 as we know array_rand outputs the keys,, how to get value from it of the random element i tried this:- <?php $n = array("lions", "tigers", "bears", "kittens"); var_dump(array_rand($n)); ?> and also how to get values, if i pass the 2nd parameter i.e. number of random keys we need,, because the array returned by it contain keys as their values Link to comment https://forums.phpfreaks.com/topic/281029-array_rand/ Share on other sites More sharing options...
Muddy_Funster Posted August 11, 2013 Share Posted August 11, 2013 $n = array('lions', 'tigers', 'bears', 'kittens'); $o = array_rand($n) echo $n[$o]; $p = array_rand($n, 3); foreach($p as $q){ echo $n[$q]; } Link to comment https://forums.phpfreaks.com/topic/281029-array_rand/#findComment-1444350 Share on other sites More sharing options...
Jaswinder Posted August 11, 2013 Author Share Posted August 11, 2013 thanx buddy... i think i sould take a rest for a while... this is how simple it is .. and my mind is not working .. thanx once again Link to comment https://forums.phpfreaks.com/topic/281029-array_rand/#findComment-1444356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.