MrXander Posted September 11, 2007 Share Posted September 11, 2007 Any help on this one guys (and girls)? I'm trying to pick a random end to my sentence from an array.... (Ignore the $homa variable, that's not really involved...) $locationArray = array("under a park bench", "next to some bushes", "in the gutter"); $randLocation = array_rand($locationArray); echo $homa.$randLocation; But all $randLocation returns is a numeric value. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/68917-solved-random-words-from-an-array/ Share on other sites More sharing options...
corbin Posted September 11, 2007 Share Posted September 11, 2007 The numeric value is a random key from the array.... Try something like: $locationArray = array("under a park bench", "next to some bushes", "in the gutter"); $randLocation = array_rand($locationArray); echo $homa.$locationArray[$randlocation]; Link to comment https://forums.phpfreaks.com/topic/68917-solved-random-words-from-an-array/#findComment-346403 Share on other sites More sharing options...
MrXander Posted September 11, 2007 Author Share Posted September 11, 2007 The numeric value is a random key from the array.... Try something like: $locationArray = array("under a park bench", "next to some bushes", "in the gutter"); $randLocation = array_rand($locationArray); echo $homa.$locationArray[$randlocation]; Spot on. Thanks Link to comment https://forums.phpfreaks.com/topic/68917-solved-random-words-from-an-array/#findComment-346407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.