jonoc33 Posted February 19, 2008 Share Posted February 19, 2008 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 More sharing options...
Sulman Posted February 19, 2008 Share Posted February 19, 2008 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 More sharing options...
jonoc33 Posted February 19, 2008 Author Share Posted February 19, 2008 Thanks, that worked. Link to comment https://forums.phpfreaks.com/topic/91844-randomizing/#findComment-470364 Share on other sites More sharing options...
rameshfaj Posted February 19, 2008 Share Posted February 19, 2008 You can store the variable in session using: $_SESSION["items"]="items";//the items can be array object too and later can be retrieved as you like............ Link to comment https://forums.phpfreaks.com/topic/91844-randomizing/#findComment-470421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.