Re: How to: If($var != '#' OR '#')
| From: | Jason Wong | Date: | Wed, 20 Nov 2002 18:27:37 +0000 |
| Subject: | Re: How to: If($var != '#' OR '#') | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125288@lists.php.net to get a copy of this message | ||
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.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
History repeats itself. That's one thing wrong with history.
*/