php打印pre,PHP Post和preincrement

本文揭示了PHP中关于$c=5; $r=$c+($c+++++$c); echo$r; 结果为19而非17的运算秘密,探讨了运算符优先级、结合性和括号对表达式计算的影响,以及PHP文档对此现象的官方解释。
摘要由CSDN通过智能技术生成

我在PHP中发现了一些奇怪的计算,例如:

$c=5;

$r = $c + ($c++ + ++$c);

echo $r;

为什么结果是19而不是17?

谢谢

解决方法:

While precedence, associativity, and grouping parentheses control the

order in which operators are applied, they do not control the order of

evaluation of the terms themselves. Unless stated explicitly in this

specification, the order in which the operands in an expression are

evaluated relative to each other is unspecified. See the discussion

above about the operators that contain sequence points. (For example,

in the full expression $list1[$i] = $list2[$i++], whether the value of

$i on the left-hand side is the old or new $i, is unspecified.

Similarly, in the full expression $j = $i + $i++, whether the value of

$i is the old or new $i, is unspecified. Finally, in the full

expression f() + g() * h(), the order in which the three functions are

called, is unspecified).

您也可以在PHP文档中找到相同的推理:

fBHjX.png

标签:php,post-increment,pre-increment

来源: https://codeday.me/bug/20190627/1305867.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值