Jump to content

Randomizing


jonoc33

Recommended Posts

Ok, as a joke to a bunch of mates on our forum we added a Water cooler (they requested it) that, if you click it, it adds a session and on the next page and I need it to come up with a random result.

 

Say for example after you click it, on the next page it shows at random 1 of these:

 

"You just drank urine."

"You just ate a bug."

"You feel refreshed."

"Someone took a dump in your cup."

"You found a coin at the bottom of your cup and accidentally drank it."

"Someone spiked your drink. You feel tipsy."

etc.

 

How would I do this?

 

Link to comment
https://forums.phpfreaks.com/topic/91844-randomizing/
Share on other sites

Put them all into an array and then get a random element:

 

$result=array();
$result[0]="You just drank urine.";
$result[1]="You just ate a bug.";
$result[2]="You feel refreshed.";
$result[3]="Someone took a dump in your cup.";
$result[4]="You found a coin at the bottom of your cup and accidentally drank it.";
$result[5]="Someone spiked your drink. You feel tipsy.";

$random=rand(0, 5);

echo $result[$random];

Link to comment
https://forums.phpfreaks.com/topic/91844-randomizing/#findComment-470354
Share on other sites

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.