note 81477 deleted from language.operators.logical by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:13:47 +0000 |
| Subject: | note 81477 deleted from language.operators.logical by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189834@lists.php.net to get a copy of this message | ||
Note Submitter: Benjamin
----
Re:Richard
I show $b printing 1 rather than "banana". Here's how I understand what's going
on.
<?php
//"||" has a greater precedence than "or"
$a=0 or $a="avocado"; //evaluated as ($a=0) or ($a="avacado")
//Since $a=0 is false, $a="avocado" is evaluated and $a is assigned the string value
"avocado".
echo "$a"; //prints "avocado"
var_dump ($a); // string(7) "avocado"
$b=0 || $b="banana"; // evaluated as $b = (0 || $b = "banana")
echo $b; //prints "1"
var_dump ($b); // bool(true)
?>