PHP演算子優先度

6635 ワード

Operator Precedence
Associativity
Operators
Additional Information
non-associative
clone new
clone and new
left
[
array()
non-associative
++ --
increment/decrement
non-associative
~ - (int) (float) (string) (array) (object) (bool) @
types
non-associative
instanceof
types
right
!
logical
left
*/%
arithmetic
left
+ - .
arithmetic and string
left
<< >>
bitwise
non-associative
<<= >>= <>
comparison
non-associative
== != === !==
comparison
left
&
bitwise and references
left
^
bitwise
left
|
bitwise
left
&&
logical
left
||
logical
left
? :
ternary
right
= += -= *=/= .= %= &= |= ^= <<= >>=
assignment
left
and
logical
left
xor
logical
left
or
logical
left
,
many uses
 
Left associativity means that the expression is evaluated from left to right, right associativity means the opposite.
Example #1 Associativity <?php
$a 
5// (3 * 3) % 5 = 4
$a true true 2// (true ? 0 : true) ? 1 : 2 = 2

$a 1;
$b 2;
$a $b += 3// $a = ($b += 3) -> $a = 5, $b = 5
?>

Use parentheses to increase readability of the code.
Note: Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a.
 
もし本当にこの時計を背負いたくないなら.直接「()」にすればいいです.省のエラーが発生しました.