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. Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/142009-solved-random-message-generator/#findComment-743585 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.