slyte33 Posted December 4, 2009 Share Posted December 4, 2009 Can anyone please tell me how I could randomly pick out messages to display? I remember seeing somewhere in a PHP guide you can use an array, but how? All help appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/184026-how-do-you-display-random-messages/ Share on other sites More sharing options...
Alex Posted December 4, 2009 Share Posted December 4, 2009 You can use array_rand. Ex: $messages = Array('Message 1', 'Message 2', 'Message 3'); echo $messages[array_rand($messages)]; Quote Link to comment https://forums.phpfreaks.com/topic/184026-how-do-you-display-random-messages/#findComment-971567 Share on other sites More sharing options...
slyte33 Posted December 4, 2009 Author Share Posted December 4, 2009 Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/184026-how-do-you-display-random-messages/#findComment-971568 Share on other sites More sharing options...
premiso Posted December 4, 2009 Share Posted December 4, 2009 If you are pulling data from a database, you can use rand() in the order by. SELECT message FROM messages ORDER BY rand() LIMIT 5 That will pull 5 random messages from the database. Quote Link to comment https://forums.phpfreaks.com/topic/184026-how-do-you-display-random-messages/#findComment-971571 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.