note 123658 deleted from language.operators.logical by cmb
| From: | cmb@php.net | Date: | Tue, 05 Mar 2019 17:12:49 +0000 |
| Subject: | note 123658 deleted from language.operators.logical by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210324@lists.php.net to get a copy of this message | ||
Note Submitter: museyib dot e at gmail dot com
----
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.
?>