PHP Operators and expressions
I. Classification of Operators
1, by Operation number classification
1.!true//Unary operators
2. $a + $b//two-dollar operator
3.true? 1:0//ternary operator
2, according to the function classification
(1) Arithmetic operators
1.+ 、-、 x,/,% (take more)
(2) String operators
1.///For example: $a = ' abc '. ' EFG ';
(3) Assignment operator
1.=//Simple Assignment
2.+=,-=, x=,/=,%=,. =//Compound assignment
3.++ ($a + +, + + $a),--($a--、--$a)//increment decrement
4.& ($a = 1; $b = &a)//reference assignment
(4) Comparison operators
1.==, = = = (constant equals),! =,!===, <> (not equal to), <, >, <=, >=
(5) Logical operators
1.//in parentheses with higher precedence than outside parentheses
2.&& (and), | | (OR),! (not), XOR (heterogeneous),
(6) Bitwise operator
1.& (Bitwise AND), | (bitwise OR), ~ (bitwise non), ^ (bitwise XOR), << (left shift), >> (right Shift)
Second, arithmetic operators
% remainder, common usage: 1) integer Division operation 2) control range of values
Example: Judging whether it is a leap year (four years a leap, a century does not leap, 400 years again leap)
% will turn the number of the two sides into an integer and divide the
% cannot use decimal or negative numbers on both sides
if (($year%4 = = 0) && ($year%100! = 0)) | | $year%400 = = 0)
echo "Leap year";
Else
echo "Common year";
Three, assignment operators
Add 10 first and then assign to yourself, equivalent to $a = $a +10
$a + = 10;
Increment decrement, increment decrement first, and then assign value
+ + $a
Assign value first, then increment decrement
$a + +
Instance
$a = 10;
$b = $a + +
$c =--$b
Results: a=11 b=9 c=9
Four, logical operators
XOR: Same as False (two true or two false = False), different for true (one true false = False)
Tips: Note the difference from or two true = True
Logical operator Short Circuit
1, &&//A false, then do not operate, must be false
2, | | One is true, then there is no operation behind it, it must be true.
fopen ("test.php", "R") or Die ("failure");
Tips: For Operators & | No short circuit characteristics
Five, bitwise operators
Bit operation: Convert integer to 32-bit binary, string to Ansca code to handle