duanraotun1674 2013-06-21 13:37 采纳率: 100%
浏览 55
已采纳

PHP后递增/递减运算符优先级

In documentation http://www.php.net/manual/en/language.operators.precedence.php it is said, that ++ and -- operators have very high precedence. But as i know, ++$x and $x++ is not the same. Moreover, $x++ should have minimal precedence, because it is calculated after everything is done:

$x = 1;
var_dump(1 and $x--); // and operator is one of last operators in the table, it will be executed before post decrement

So, post- increment/decrement operators should be in this table in the bottom?

  • 写回答

1条回答 默认 最新

  • douzhangcuo2174 2013-06-21 13:44
    关注

    Yes. If the operators are placed before the variable then the variable is changed before any other order of operations.

    $a=4;
    $x=++$a + 6; will result in $x=11 and $a=5
    $x=$a++ + 6; will result in $x=10 and $a=5
    

    When the operators are in front it takes precedence over all other operators. You can find a simple explanation at the following site as well:

    http://www.php.net/manual/en/language.operators.increment.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100