Perad Posted November 19, 2007 Share Posted November 19, 2007 I have an array which has $key and $values set. I want to randomly select one of these values. How would I do this? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 19, 2007 Share Posted November 19, 2007 $select = rand(0, count($arr) - 1); echo $arr[$select]; Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 19, 2007 Share Posted November 19, 2007 Like this: $array_name[rand(0, count($array_name)-1 )]; -- rand(min,max) selects a random number in between min, and max. count(array) counts how many arrays values are in an array Quote Link to comment Share on other sites More sharing options...
Perad Posted November 19, 2007 Author Share Posted November 19, 2007 Wes, in regards to your answer, what are the square brackets for? Quote Link to comment 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.