--- Jason Wong <[EMAIL PROTECTED]> wrote:
> On Thursday 21 November 2002 01:34, Ryan Gallagher wrote:
> > 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.
>
> 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!
Your boolean math may be rusty, but you are correct. :-) I think,
however, that he was simply focusing on a literal interpretation of
the original poster's code without considering if it made sense.
If you want to exclude 2 *and* exclude 8 (saying things aloud can
sometimes reveal obvious logic problems), just write it like this:
if($_GET["sc"] != 2 && $_GET["sc"] != 8)
{
...
}
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php