Re: IF with multiple values for a variable
| From: | Jochem Maas | Date: | Thu, 14 Jun 2007 10:12:00 +0000 |
| Subject: | Re: IF with multiple values for a variable | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-256975@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
> On Wed, 2007-06-13 at 13:57 -0400, tg-php@gryffyndevelopment.com wrote:
>> double pipes constitutes an "OR" operation. You can use the keyword OR as well.
>> Also, && and AND are the same as well.
>>
>> http://us.php.net/manual/en/language.operators.logical.php
>
> They aren't exactly the same. Make sure and read the order of precedence
> note. The following, for example, are not equivalent:
I knew that they we're not exactly the same due to order of precedence, but
I ran Robbert's code snippet and found that my assumptions about the outcome incorrect!
my assumption was that '=' had lower precedence that 'and' ... somehow that felt
right,
obviously I was wrong.
it took me a few seconds to see the error of my ways :-) maybe there are other
that are confused ... maybe the output of following little snippet might help to clarify:
<?php
$true = true;
$false = false;
$test1 = $true && $false;
$test5 = ($test2 = $true and $false);
$test3 = ($true && $false);
$test4 = ($true and $false);
var_dump($test1, $test2, $test3, $test4, $test5);
?>
thanks to Robbert for the brainteaser ;-)