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? Link to comment https://forums.phpfreaks.com/topic/45600-random-text/ 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]; Link to comment https://forums.phpfreaks.com/topic/45600-random-text/#findComment-221424 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 Link to comment https://forums.phpfreaks.com/topic/45600-random-text/#findComment-221430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.