An expression
Almost anything written is an expression, but the simplest and most precise way to define an expression is "anything that has value."
Arithmetic operators
Commonly used in PHP are: + 、-、 *,/,% (modulo, get the remainder)
Left +-*/% a+=3 equivalent to a=a+3 other in turn
comparison Operators
$a = = $b equals True if $ A equals $b
$a = = = $b Congruent true if $ A equals $b, and their type is the same
$a! = $b Unequal to True if $ A is not equal to $b
$a <> $b True if $ A is not equal to $b
$a!== $b non-congruent true if $ A equals $b, or their type is not the same
$a < $b less than true if $ A is strictly less than $b
$a > $b greater than True if $ A is strictly greater than $b
$a <= $b less than or equal to true if $ A is less than or equal to $b
$a >= $b greater than or equal to true if $ A is greater than or equal to $b
logical Operators
$a && $b and logic and true if $ A and $b are true
$a | | $b or logic, or true if $ A and $b any one, the result is true
! $a not logical not if $ A is not true, the result is true
Ternary operators
Basic syntax:
Expression 1? Expression 2: Expression 3
Rule: If the operation result of expression 1 is true, take the value of expression 2, otherwise take the value of expression 3, the expression 2,3 can be a specific value or a formula or function.
String operators
There are 2 string operators, using the Join operator ("." ), a small dot.
<?php
$a =hello;
$b =world;
$c = $a. $b;
Echo $c;
?>
Then output: Hello World
“.” Both sides, regardless of whether it is a string, as long as "." will be processed by the type of the string, and their contents are stitched up.
type operator
Basic syntax: instanceof is used to determine whether a PHP variable belongs to an instance of a class, and in actual development we may need to determine whether a variable is a type, which is often used in object-oriented development. "The back is fine."
precedence level of operators
rank from low to high
PHP operator Knowledge points