my8code Posted November 4, 2010 Share Posted November 4, 2010 <? $array = array('eggs', 'bacon', 'football', 'baseball', 'ford', 'toyota'); $rand_index = mt_rand(0, count($array) / 2 - 1) * 2; ?> <?php echo "$array[$rand_index]"; ?><?php echo "$array[$rand_index+1]"; ?> i dunno why this doesn't work. I want to echo both values three of the pairs such as eggs bacon or football baseball Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 4, 2010 Share Posted November 4, 2010 Use array_chunk and shuffle. <?php $array = array('eggs', 'bacon', 'football', 'baseball', 'ford', 'toyota'); $array = array_chunk($array, 2); shuffle($array); echo $array[0][0] . ' and ' . $array[0][1]; ?> Quote Link to comment Share on other sites More sharing options...
mikecampbell Posted November 4, 2010 Share Posted November 4, 2010 Get rid of the double quotes in your echo statements. 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.