Re: The || Operator (alternatives to the)
| From: | Radu Manole | Date: | Mon, 26 May 2003 15:45:38 +0000 |
| Subject: | Re: The || Operator (alternatives to the) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148989@lists.php.net to get a copy of this message | ||
or
$you='some';
$words=array('few','some','one','more','less');
if (in_array($you,$words)){
echo 'yes';
}else{
echo 'no';
}
----- Original Message -----
From: "Joel Rees" <joel@alpsgiken.gr.jp>
To: <php-general@lists.php.net>
Sent: Monday, May 26, 2003 10:21 AM
Subject: Re: [PHP] The || Operator (alternatives to the)
> > $you = "some";
> > if ($you == ("few" || "some" || "one")) {
> > echo "yes";
> > }else{
> > echo "no";
> > }
> >
> > How can I make it print out "yes" if $you is equal to "few",
> > "some", or
> > "one"?
>
> One more option, may be useful if your list is long, or if your
> association is to more than just "yes" --
>
> $someWords =
> array(
> "few" => "yes",
> "some" => "yes",
> "one" => "yes",
> "many" => "maybe"
> );
>
> $you = "some";
>
> $theWord = $someWords[ $you ];
>
> if ( isset( $theWord ) )
> { echo $theWord;
> }
> else
> { echo "no";
> }
>
> --
> Joel Rees, programmer, Kansai Systems Group
> Altech Corporation (Alpsgiken), Osaka, Japan
> http://www.alpsgiken.co.jp
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>