The first bullet in PHP is the php bit operator "|" and the logical operator "|. In php, | is a php bit operator, | is the code of the logical operator bit operator :? Php $ a0; $ b0; if ($ a3 | $ b3) {$ a ++; $ B ++;} echo $ a.,. $ B; output 4, 4? Compare the code. The following is the logic in php. "|" is the php bit operator, and "|" is the logical operator.
Bitwise operator code:
$ A = 0;
$ B = 0;
If ($ a = 3 | $ B = 3 ){
$ A ++;
$ B ++;
}
Echo $ a. ','. $ B; // output 4. 4
?>
The following code compares the code with the logic operator:
$ A = 0;
$ B = 0;
If ($ a = 3 | $ B = 3 ){
$ A ++;
$ B ++;
}
Echo $ a. ','. $ B; // output 1, 1
?>
In the first example, "$ a = 3 | $ B = 3", because "|" has a higher priority than the value assignment operator, therefore, the operation order can be written as "$ a = (3 | $ B = 3)". first, $ B is assigned as 3, and $ a is assigned a value for the result of 0100 | 0100, $ a is still 0100. Therefore, $ a is assigned a value of 0100, that is, 3 in decimal format. if the value is successfully assigned, true is returned. if the content in the code block is executed, $ a is automatically added, $ B is also self-added, so $ a = 4, $ B = 4
In the second example, it can also be seen as "$ a = (3 | $ B = 3)". first, 3 | $ B = 3 returns true, "|" causes short circuit, "|" the first 3 is true, "$ B = 3" is not executed, so $ B is still 0 at this time, $ a is a Boolean value of true. if the value is successfully assigned, true is returned. if the content in the code block is executed, $ a ++ is also true, and $ B ++ is 1. therefore, $ a = 1, $ B = 1
From zdrjlamp
Operator, | it is a php bit operator, | it is the logic operator bit operator code :? Php $ a = 0; $ B = 0; if ($ a = 3 | $ B = 3) {$ a ++; $ B ++ ;} echo $ .,. $ B; // output 4? Compare the code. The following is the logic...