note 123658 added to language.operators.logical
| From: | museyib dot e at gmail dot com | Date: | Tue, 05 Mar 2019 11:45:14 +0000 |
| Subject: | note 123658 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210323@lists.php.net to get a copy of this message | ||
Maybe this mentioned before:
1. If left side of 'and' operator returns 'false', then right side is not
evaluated, because it doesn't matter that is true or false: conditional statement will not be
executed:
<?php
$a=0;
$ab=0;
if(a and ++b)
{
echo "Hello<br>"; //It will not print.
}
echo '$b: '.$b."<br>"; //Output: $b: 0.
?>
<?php
$a=1;
$ab=0;
if(a and ++b)
{
echo "Hello<br>"; //It will print.
}
echo '$b: '.$b."<br>"; //Output: $b: 1.
?>
2. If left side of 'or' operator returns 'true', then right side is not
evaluated, because it doesn't matter that is true or false: conditional statement will be
executed.
<?php
$a=1;
$ab=0;
if(a or ++b)
{
echo "Hello<br>"; //It will print.
}
echo '$b: '.$b."<br>"; //Output: $b: 0.
?>
<?php
$a=0;
$ab=0;
if(a or ++b)
{
echo "Hello<br>"; //It will print.
}
echo '$b: '.$b."<br>"; //Output: $b: 1.
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.194 (proxied: 5.191.53.160)
----
Manual Page -- http://php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/123658
Del: integrated -- https://master.php.net/note/delete/123658/integrated
Del: useless -- https://master.php.net/note/delete/123658/useless
Del: bad code -- https://master.php.net/note/delete/123658/bad+code
Del: spam -- https://master.php.net/note/delete/123658/spam
Del: non-english -- https://master.php.net/note/delete/123658/non-english
Del: in docs -- https://master.php.net/note/delete/123658/in+docs
Del: other reasons-- https://master.php.net/note/delete/123658
Reject -- https://master.php.net/note/reject/123658
Search -- https://master.php.net/manage/user-notes.php