PHP 运算符 优先级
2010-07-28 11:00
369 查看
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 |
Example #1 Associativity
<?php $a = 3 * 3 % 5; // (3 * 3) % 5 = 4 $a = true ? 0 : true ? 1 : 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[/b]: 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.
如果真的不想背这个表的话。 直接在“()”就行了。省的出现错误。
相关文章推荐
- PHP 运算符优先级
- PHP 关于访问控制的和运算符优先级介绍
- PHP 运算符的优先级
- PHP学习笔记——运算符的优先级和表达式;
- 【踩坑】PHP中关于运算符优先级使用中可能遇到的问题
- 由逻辑异或运算符而发现的PHP诡异运算符优先级
- PHP学习 运算符与运算符优先级
- PHP 关于访问控制的和运算符优先级介绍
- PHP学习 运算符与运算符优先级
- PHP 运算符 OR 和 || 优先级的问题
- PHP的运算符的优先级
- php——学习笔记,运算符优先级
- 【php手册:运算符】运算符优先级
- 关于php运算符优先级问题(php不完全遵守运算符优先级)
- PHP数组合并:[“+”运算符]、[array_merge]、[array_merge_recursive]区别
- C/C++运算符及其优先级
- PHP基本语法、变量、数据类型、运算符
- js中运算符的优先级
- Python按位运算符,字典,运算符优先级的基本总结
- PHP运算优先级——神一般的设定