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 Link to comment https://forums.phpfreaks.com/topic/217717-echoing-array-index-and-getting-a-blank-page/ 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]; ?> Link to comment https://forums.phpfreaks.com/topic/217717-echoing-array-index-and-getting-a-blank-page/#findComment-1130130 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. Link to comment https://forums.phpfreaks.com/topic/217717-echoing-array-index-and-getting-a-blank-page/#findComment-1130131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.