Re: Random output?

From: Date: Thu, 28 Dec 2000 02:59:25 +0000
Subject: Re: Random output?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32032@lists.php.net to get a copy of this message
Hey there, Here's one way to do it : <?php $player_name = 'philip'; $club_name = 'club mad'; $sad = array("$player_name is upset about low wages at $club_name", "Well, $club_name likes $player_name but pays low wages"); $happy = array("$player_name is happy! about the $club_name pay raise", "Wow, that $club_name pay raise makes $player_name happy"); $damn = array ("$player_name is not happy about $club_name wage offer", "Weak wages offered for $player_name at $club_name!"); function randSaying($sayings) { srand ((double) microtime() * 10000000); $key = array_rand($sayings,1); Return $sayings[$key]; } // To print from $sad : print randSaying($sad); ?> Regards, Philip .sig [ I make mistakes all the time. ] On Thu, 28 Dec 2000, ScreamKing wrote: > 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 (#32032) next »