The similarities and differences between & and && in PHP logic operators
PHP has 5 arithmetic operators (+-*/%), 6 assignment operators (+ = = *=/=%=. =), 8 comparison operators (= = = < > <= >=! = <>!==), and 6 logical operators (such as &&, | |, &, |,!. Where logic and & can be written and, logically or | written or, and some other operators ([email protected] execution operator anti-quote "-not single quotes, string operators.) ++/--、 ternary operator with. =, increment/decrement operator?:).
For operator Precedence, refer to the relevant documentation.
The similarities and differences between & and && in PHP
4 && (+ + $a >10)) {}//output 11.echo $a;? >
4 and (+ + $a >10)) {}//output is 11.echo $a;? >**************************************************************
4 && (+ + $a <10)) {}//output 11.echo $a;? >
4 & (+ + $a <10)) {}//output 11.echo $a;? >*********************************************************
10) {}//output is 10.echo $a;? >
10) {}//output is 11.echo $a;? >*******************************************************************
*******************************************************************
Expression A $ A && $b, expression two $ A & $b
1, the same point: two expressions are when $ A, $b are true, the expression is true. The two operators have no effect on the result of this expression.
2, different points: the expression of $ A && $b && before the $ A is false, determined that the expression is false, the logical operator && after the $b is no longer evaluated, that is, the so-called operator "short circuit". And for the expression $ A & $b, regardless of the & before the true and false, the expression after the $b still to be calculated. Whether the $b after the logical operator is run may affect subsequent data and program results.
For logical operators | | and |, the similarities and differences ibid.