Re: How to: If($var != '#' OR '#')
| From: | Ryan Gallagher | Date: | Wed, 20 Nov 2002 18:59:24 +0000 |
| Subject: | Re: How to: If($var != '#' OR '#') | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125298@lists.php.net to get a copy of this message | ||
Quoting Jason Wong <php-general@gremlins.biz>:
> On Thursday 21 November 2002 01:34, Ryan Gallagher wrote:
>
> > Try:
> >
> > if( ( $_GET['sc'] != 2 ) OR ( $_GET['sc'] != 8 ) ){
> > /*
> > * Do Foo provided sc is anything but a 2 or 8
> > */
> > do foo;
> > }
> >
> > Assuming of course that you meant to exclude cases of 2 or 8. It's a bit
> > hard to tell what your intended event for 8 is.
>
> The above would not have the intended effect. My boolean maths is extremely
> rusty but I think it is equivalent to saying:
>
> if (!($_GET['sc'] == 2 AND $_GET['sc'] == 8))
>
> Which means your code above is *always* TRUE, so do foo is always executed!
>
> In any case you can easily test it by mentally plugging in values 1 to 8 for
>
> $_GET['sc'] and evaluating it for yourself.
I'll shut up now, teaches me to reply to this list too early in the morning and
without coffee. ;-)
BTW, what I posted would ALWAYS execute, because of _OR_. If it's 2, then it's
not 8, so one of the two sides would be true.
Here's a corrected one:
if( ( $_GET['sc'] != 2 ) AND ( $_GET['sc'] != 8 ) ){
/*
* Do Foo provided sc is anything but a 2 or 8
*/
do foo;
}
--
Ryan T. Gallagher
ryan@studiesabroad.com
International Studies Abroad
http://www.studiesabroad.com
(512)480-8522