Mutley Posted April 4, 2007 Share Posted April 4, 2007 If I have 3 lines, say: echo "Yes"; echo "Maybe"; echo "No"; How do I make this into one variable that randomly picks 1 of the 3 echos above? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 4, 2007 Share Posted April 4, 2007 $text = array("Yes", "Maybe", "No"); //try $id = array_rand($text); echo $text[$id]; //or shuffle($text); echo $text[0]; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 Create an array <?php $a = array('Yes','Maybe','No'); ?> and use the array_rand() function to select a random entry: <?php echo $a[array_rand($a)]; ?> Ken Quote Link to comment 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.