First, the PHP operator
PHP has a rich set of operators, most of which come directly from the C language. Depending on the function, operators can be divided into: arithmetic operators, string operators, assignment operators, bitwise operators, conditional operators, and logical operators. When the various operators are in the same expression, their operations have a certain precedence.
(1) Arithmetic operations
+ - * / % ++ --
(2) String operators
There is only one string operator. (dot) is the end of the English period. It can concatenate strings together, form new strings, or concatenate strings to numbers, and the type will automatically convert.
View Source
Print?
1. $a = "Dawanganban";
2. $b = "123";
3. Echo $a. $b; Output Result: dawanganban123
(3) Assignment operator
View Source
Print?
01. = + = = *=/=%=. =
02.
03.
04.
$a = "Dawanganban";
. $a. =1;
. $a. =2;
$a. =3;
$a. Echo $b; Output Result: dawanganban123
(4) Bitwise operator
& | ~ ^ << >>
(5) Comparison operators
> < >= <= = = = = <> = = =!==
<>: Not equal to and! = Same
= = =: Identical, values equal and type consistent
! = =: Non-identical, value not equal or type inconsistent
View Source
Print?
1. Echo 5 = = "5"; True PHP is a weakly typed language (the variables in JS are similar)
2. echo 5 = = = "5"; False is exactly equal to
(6) Logical operation
and (Logical AND) or (logical OR) XOR (logical XOR) && (logic and) | | (Logical OR)! (Logical non)
View Source
Print?
1. Var_dump (5 && ""); False
2. Var_dump (5 && "2"); True
3. Var_dump (5 | | ""); True
4. Var_dump (0 xor 1); True
5. Var_dump (0 xor 0); False
6. Var_dump (1 xor 1); False