note 81477 added to language.operators.logical
| From: | Benjamin at osu1 dot php dot net | Date: | Fri, 29 Feb 2008 17:48:41 +0000 |
| Subject: | note 81477 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136605@lists.php.net to get a copy of this message | ||
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)
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.193.185.164
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/81477
Del: integrated -- https://master.php.net/note/delete/81477/integrated
Del: useless -- https://master.php.net/note/delete/81477/useless
Del: bad code -- https://master.php.net/note/delete/81477/bad+code
Del: spam -- https://master.php.net/note/delete/81477/spam
Del: non-english -- https://master.php.net/note/delete/81477/non-english
Del: in docs -- https://master.php.net/note/delete/81477/in+docs
Del: other reasons-- https://master.php.net/note/delete/81477
Reject -- https://master.php.net/note/reject/81477
Search -- https://master.php.net/manage/user-notes.php