首页 / PHP / 一个php运算符优先级有关问题
一个php运算符优先级有关问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了一个php运算符优先级有关问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1327字,纯文字阅读大概需要2分钟。
内容图文
![一个php运算符优先级有关问题](/upload/InfoBanner/zyjiaocheng/216/6bbf31c1b57445f991db0d9d34f134c5.jpg)
先看一个运算符优先级表
Operator Precedence(运算符优先级)
引用Associativity Operators Additional Information
non-associative clone new clone and new
left [ array()
non-associative ++ -- increment/decrement
right ~ - (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
引用&& 优先于 = 优先于 and
但是
引用$a = 100 && $b = 200
按照运算符优先级规则顺序应该是
引用$a = ( ( 100 && $b ) = 200 )
但是php里有规定,
引用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.
所以实际效果是
引用( $a = 100 )&& ( $b = 200 )
相当于把 && 变成了 and
另外,引用鸟哥的一个例子
引用最后, 顺便说一下, PHP对应于T_BOOLEAN_AND 还定义了 T_LOGICAL_AND(and) 和 T_LOGICAL_OR(or) , 这俩个的优先级都低于等号, 于是就会有了, 很多PHP入门教材示例代码中经典的:
$result = mysql_query(*) or die(mysql_error());
内容总结
以上是互联网集市为您收集整理的一个php运算符优先级有关问题全部内容,希望文章能够帮你解决一个php运算符优先级有关问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。