Jump to content

[SOLVED] Random Words From An Array


MrXander

Recommended Posts

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

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.