Re: if statement with or comparison (newbie)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No, just try it. Since the returned value cannot have to values at once, whatever it comes it will succeed either one or both and being joined by an or, any single one that succeeds make the whole succeed. Just try it:

Returned value        result
red                            true or true => true
black                    false or true => true
white                    true or false => true

That is why in my e-mail I insisted that the best thing you can do with complex booleans is try to straighten the logic and avoid too many negations, which tend to turn the logic upside down.

Satyam

----- Original Message ----- From: "Kevin Murphy" <php@xxxxxxxxxxxxxxxxxx>
To: "php" <php-general@xxxxxxxxxxxxx>
Cc: "JD" <jd_borozo@xxxxxxxxxx>
Sent: Friday, September 08, 2006 11:25 PM
Subject: Re:  if statement with or comparison (newbie)


Shouldn't that be this instead:


     if (($_REQUEST['id'] != "black") OR ($_REQUEST['id'] !=
"white")) {

         echo "wrong color";

     } else {

         echo "right color";

     }


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Sep 8, 2006, at 2:28 PM, Prathaban Mookiah wrote:

Let me rephrase it. Your color should be black or white to be the
right
colour. Is this correct?

In that case you should change it to

     if ($_REQUEST['id'] != "black" AND $_REQUEST['id'] != "white") {

         echo "wrong color";

     } else (

         echo "right color";

     }

----- Original Message -----
From: "JD" <jd_borozo@xxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Friday, September 08, 2006 5:03 PM
Subject:  if statement with or comparison (newbie)


I'm trying to set up a simple conditional, something like this:

If my_variable is NOT equal to (black or white)
   echo "wrong color"
else
   echo "right color"

Here is what I have tried:

    if ($_REQUEST['id'] != ("black" or "white")) {

        echo "wrong color";

    } else (

        echo "right color";

    )

However, no matter what I enter, I always get response "right color".

I should add that if I change the if statement to:

    if ($_REQUEST['id'] != ("black"))

then I get "right color" when I enter "black" and "wrong color" for
everything else.

Would you please point out what's the trivial thing I'm missing
here...

jd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux