This article introduces the use and analysis of basic PHP operators. For more information, see
1. arithmetic operators: +,-, *,/, and %.
2. increment/decrease operators: for example, $ a ++, $ a --, ++ $ a, -- $.
For example:
$ A = 10;
$ B = 5;
$ C = $ a ++; // assign values first and then auto-increment. $ C = $ a, $ a = $ a + 1
$ D = $ B --; // assign values first, and then subtract from them. $ D = $ B, $ B = $ A-1
Echo '$ a ='. $ a. "|". '$ c ='. $ c .'
'; // $ A = 11, $ c = 10
Echo '$ B ='. $ B. "|". '$ d ='. $ d .'
'; // $ B = 4, $ d = 5
?>
$ A = 10;
$ B = 5;
$ C = ++ $ a; // auto-increment first, and then assign a value. $ A = $ a + 1, $ c = $
$ D = -- $ B; // first auto-subtract and then assign a value. $ B = $ A-1, $ d = $ B
Echo '$ a ='. $ a. "|". '$ c ='. $ c .'
'; // $ A = 11, $ c = 11
Echo '$ B ='. $ B. "|". '$ d ='. $ d .'
'; // $ B = 4, $ d = 4
?>
3. Comparison operator: Reference Document
4. logical operators:
For example:
$ A = 10; $ B = 7;
If ($ a ++> 8 | $ B ++> 7) {// $ a ++> 8 is true, $ B ++> 7 is not executed.
Echo 'OK! ';
}
Echo 'a = '. $ a.' B = '. $ B; // output OK, a = 11, B = 7
Change
$ A = 10; $ B = 7;
If ($ a ++> 10 & $ B ++> 7) {// $ a ++> 8 is false, $ B ++> 7 is not executed.
Echo 'OK! ';
}
Echo 'a = '. $ a.' B = '. $ B; // a = 11, B = 7
Details: and & all indicate logic and where are their differences?
Mainly reflected in priority
And priority and <= <& or <= <| for example:
$ A = false | true; // & >=> and; compare false first | true, and then assign a value.
$ B = false or true; // | |>=> or; first, assign $ B = false and then compare. Therefore, the result is false.
Var_dump ($ a, $ B); // bool (true) bool (false)