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 Quote 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]; } Quote Link to comment https://forums.phpfreaks.com/topic/281029-array_rand/#findComment-1444350 Share on other sites More sharing options...
Solution Jaswinder Posted August 11, 2013 Author Solution 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 Quote Link to comment https://forums.phpfreaks.com/topic/281029-array_rand/#findComment-1444356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.