The frontend learns PHP operators and PHP operators. PHP operators, PHP operators, directory arithmetic operators, value assignment operators, comparison operators, ternary operators, logical operators, string operators, error control operators, increment operators, and PHP operators
Directory arithmetic operator value assignment operator comparison operator ternary operator logical operator string operator error control operator increment/decrease operator array operator definition
An operator is the identifier of an operation. PHP operators include arithmetic operators, value assignment operators, comparison operators, ternary operators, logical operators, string concatenation operators, error control operators, incrementing and decreasing operators, and array operators.
Arithmetic operators
+ (Addition) $ x + $ y-(subtraction) $ x-$ y * (multiplication) $ x * $ y/(division) $ x/$ y % (modulo) $ x % $ y
Value assignment operator
There are two assignment operators in PHP: direct assignment "=" and reference assignment "&"
[1] direct assignment
Direct value assignment "=" assigns the value of the right expression to the number of operations on the left. It copies the value of the expression on the right and submits it to the number of operations on the left. In other words, first apply for a piece of memory for the number of operations on the left, and then put the copied value in the memory.
x = yx += yx -= yx *= yx /= yx %= y
[2] reference assignment
Reference assignment & means that both variables point to the same data. It will make the two variables share a piece of memory. if the data stored in this memory changes, the values of the two variables will change.
"; // Test content 1 echo $ c ."
"; // Test content 2?>
Comparison Operators
Comparison operators are mainly used for comparison operations.
= Equal to = all! = Not supported <> not supported! ==Incomplete> greater than <<>=greater than or equal to <= less than or equal
";//bool(true) var_dump($a === $b); echo "
";//bool(false) var_dump($a != $b); echo "
";//bool(false) var_dump($a <> $b); echo "
";//bool(false) var_dump($a !== $b); echo "
";//bool(true) var_dump($a < $b); echo "
";//bool(false)?>
Ternary operators
"? : "A ternary operator is a comparison operator. for an expression (expr1 )? (Expr2) :( expr3). If the value of expr1 is true, the value of this expression is expr2; otherwise, it is expr3.
= 60? "Pass": "fail"; echo $ B; // Pass?>
Logical operators
Logical operators are mainly used for logical operations.
And is different from or xor & | or! Non
"; Echo ($ a or $ c); // 1 echo"
"; Echo ($ a xor $ c xor $ d); // 1 echo"
"; Echo (! $ C? "Through": "not through"); // through echo"
"; Echo ($ a & $ d? "Pass": "Do not pass"); // do not pass echo"
"; Echo ($ B | $ c | $ d? "Pass": "Fail"); // Pass?>
String operators
The string concatenation operator is used to connect two strings.
[1] concatenation operator (.)
[2] concatenate the value assignment operator (. =)
Error Control Operator
PHP provides an error control operator @. for expressions that may encounter errors during running, place @ before a PHP expression if you do not want the error message to be displayed. If the track_error feature is activated, any error information generated by the expression is stored in the variable $ php_errormsg, which is overwritten every time an error occurs.
[Note] The error control prefix @ does not shield information about resolution errors. it cannot be placed before the definition of a function or class, or used for condition structures such as if and foreach.
Increment/decrease operator
++ $ X increment before $ x ++ increment after -- $ x decrease before $ x -- decrease after
Array operators
Used to compare arrays
+ Union = equal = all! = Not equal <> not equal! = Incomplete
"red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); $z = $x + $y; var_dump($z);//array(4) { ["a"]=> string(3) "red" ["b"]=> string(5) "green" ["c"]=> string(4) "blue" ["d"]=> string(6) "yellow" } echo "
";var_dump($x == $y);//bool(false)echo "
";var_dump($x === $y);//bool(false)echo "
";var_dump($x != $y);//bool(true)echo "
";var_dump($x <> $y);//bool(true)echo "
";var_dump($x !== $y);//bool(true)?>
Values directory arithmetic operator value assignment operator comparison operator ternary operator logical operator string operator error control operator incremental delivery...