If the operator has the same priority, its combination direction determines whether to evaluate from right to left or from left to right. See the following example. The following table lists operators based on their priorities from high to low. Operators in the same row have the same priority. in this case, their union direction determines the order of value. The operator priority specifies how closely two expressions are bound ". For example, the result of expression 1 + 5*3 is 16 instead of 18 because the priority of the multiplication sign ("*") is higher than that of the plus sign ("+. If necessary, use parentheses to forcibly change the priority. Example: (1 + 5) the value of * 3 is 18.
If the operator has the same priority, its combination direction determines whether to evaluate from right to left or from left to right. See the following example.
The following table lists operators based on their priorities from high to low. Operators in the same row have the same priority. in this case, their union direction determines the order of value.
Operator priority
Additional information of combined direction operators
No clone new clone or new
Left [array ()
Right ++ --~ (Int) (float) (string) (array) (object) (bool) @ Type and increment/decrease
No instanceof type
Right! Logical operators
Left */% arithmetic operator
Left +-. arithmetic operators and string operators
Left <> bitwise operator
None =! ===! ==<> Comparison operators
Left & bit operators and references
Left ^ bit operator
Left | bitwise operator
Left & logical operators
Left | logical operator
Left? : Ternary operator
Right = + =-= * =/=. =%=<<=>==> value assignment operator
Left and logical operators
Left xor logical operator
Left or logical operators
Left, used in multiple places
For operators with the same priority, the left union direction means that the value is calculated from left to right, and the right union direction is vice versa. For operators with the same priority without the direction of integration, this operator may not be able to combine with itself. For example, in PHP, 1 <2> 1 is an invalid statement, while 1 <= 1 = 1 is not. Because the priority of the T_IS_EQUAL operator is lower than that of the T_IS_SMALLER_OR_EQUAL operator.
Example #1 integration direction
$a = 5, $b = 5// mixing ++ and + produces undefined behavior$a = 1;echo ++$a + $a++; // may print 4 or 5?>
Use parentheses to enhance the readability of the code even if it is not strictly required.
Note:
Although = has a lower priority than most other operators, PHP still allows expressions similar to the following: if (! $ A = foo (). In this example, the return value of foo () is assigned to $.
Example: