in PHP, "|" is a PHP bitwise operator, "| |" As a logical operator
Bit operator Code:
$a = 0;
$b = 0;
if ($a =3 | $b =3) {
$a + +;
$b + +;
}
echo $a. ', '. $b; Output
?>
Compare the code with the following code for the logical operator:
$a = 0;
$b = 0;
if ($a =3 | | $b =3) {
$a + +;
$b + +;
}
echo $a. ', '. $b; Output
?>
In the above two examples, the first example, "$a = 3 | $b =3″ due to "|" Has a higher precedence than the assignment operator, so the order of operations can be written as "$a = (3 | $b =3) ", first $b is assigned a value of 3, and $ A is binary number 0100 | The result assignment of 0100 is still 0100, so $ A at this time is assigned a value of 0100, that is, the decimal 3, the assignment succeeds, returns True, executes if the contents of the block, $a self-addition, $b also self-added, so, $a =4, $b =4
In the second example, the same can be seen as "$a = (3 | | $b = 3)", First 3| | $b = 3 Returns True, "| |" Cause a short circuit, "| |" The previous 3 is already true, "$b =3″ is no longer executed, so at this point $b is still 0, $a is Boolean type true, the assignment succeeds, returns True, executes the contents of the If code block, $a + + is true, $b + + is 1, so $a =1, $b =1
Excerpted from Zdrjlamp
http://www.bkjia.com/PHPjc/478288.html www.bkjia.com true http://www.bkjia.com/PHPjc/478288.html techarticle in PHP, | is the PHP bitwise operator, | | Is the logical operator bit operator code:? php $a = 0; $b = 0; if ($a =3 | $b =3) {$a + +, $b + +;} echo $a.,. $b; Output? Compare the code, the following is the logic ...