forumnz Posted January 22, 2009 Share Posted January 22, 2009 How would I achieve this is PHP? I just need to write a script which selects a random message from an array. How is this done. Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/142009-solved-random-message-generator/ Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 I would do something like $array = array("quote1","quote2"); shuffle($array); echo $array[rand(0,count($array))]; Edit: If you are getting the quotes from a db then use ORDER BY RAND() in your query Link to comment https://forums.phpfreaks.com/topic/142009-solved-random-message-generator/#findComment-743584 Share on other sites More sharing options...
premiso Posted January 22, 2009 Share Posted January 22, 2009 array_rand Link to comment https://forums.phpfreaks.com/topic/142009-solved-random-message-generator/#findComment-743585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.