RE: [PHP] Random output?

From: Date: Fri, 01 Dec 2000 01:22:28 +0000
Subject: RE: [PHP] Random output?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32028@lists.php.net to get a copy of this message
You could put all of your strings into an array, then use a combination of array_rand() and eval() to get the string back out... <? $name = "John Holmes"; $msg[0] = "Hello $name"; $msg[1] = "Tag $name"; $msg[2] = "Hey $name"; $rand = array_rand($msg); eval("\$text = \"$rand[0]\";"); echo $text; ?> Check on the eval() statement, but I think that's how it goes... ---John Holmes... -----Original Message----- From: ScreamKing [mailto:goodfella_gf@hotmail.com] Sent: Thursday, December 28, 2000 9:18 AM To: php-general@lists.php.net Subject: [PHP] Random output? Hi All, I need a little help with an output problem. I want to output a message (see below) but would like to use more than one variation of the same statement, as the message will become too repetitive. Is there a way I can randomly choose a message for the same if expression? At the moment, there is only one variation for the below, but I would love to increase that to randomly chosen ones. Any help is much appreciated. echo "<br><b>PLAYER STATUS</b><br>"; if ($wage == "$current_wage") { echo "Despite being delighted at signing for $club_name, $player_name expressed his disappointment at not securing a higher wage.<BR>\n"; } elseif ($wage > "$current_wage") { echo "$player_name has stated that he is delighted with the pay-rise given to him in his new contract.<BR>\n"; } elseif ($wage < "$current_wage") { echo "$player_name has admitted that while he is disappointed by the wage offer, he is still looking forward to playing for $club_name.<BR>\n"; } else { echo "$player_name has stated the his contract details have satisfied his personal needs."<BR>\n"; } Cheers, SK

« previous php.general (#32028) next »