超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<表达式算术运算符>
Last updated: Fri, 22 Jun 2007

章 15. 运算符

运算符优先级

运算符优先级指定了两个表达式绑定得有多“紧密”。例如,表达式 1 + 5 * 3 的结果是 16 而不是 18 是因为乘号(“*”)的优先级比加号(“+”)高。必要时可以用括号来强制改变优先级。例如:(1 + 5) * 3 的值为 18

下表从低到高列出了运算符的优先级。

表格 15-1. 运算符优先级

结合方向运算符
,
or
xor
and
print
= += -= *= /= .= %= &= |= ^= ~= <<= >>=
? :
||
&&
|
^
&
== != === !==
< <= > >=
<< >>
+ - .
* / %
! ~ ++ -- (int) (float) (string) (array) (object) @
[
new

注: 尽管 != 的优先级高,PHP 仍旧允许类似如下的表达式:if (!$a = foo()),在此例中 foo() 的输出被赋给了 $a




add a note add a note User Contributed Notes
运算符
yasuo_ohgaki at hotmail dot com
09-Mar-2001 05:58
Pay additional attention that precedence is listed from LOWER to HIGHER. Compiler language books list precedence opposite order. (At least, language books that I have, C/C++/Java. Perl book is the same order. I prefer precedence listed from higher to lower, not a big deal though)

<表达式算术运算符>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22