PHP中的预增量和后增量 [英] pre-increment and post-increment in PHP

查看:116
本文介绍了PHP中的预增量和后增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下语句的结果应该给出9 :(使用java或js或c ++)

the result of the following statement should give 9 : (using java or js or c++)

i = 1;
i += ++i + i++ + ++i;
//i = 9 now

但在php中

相同的陈述会给出12?!

the same statements will give 12 ?!

$i = 1;
$i +=  ++$i + $i++ + ++$i;
echo $i;

这是一个错误还是任何人都可以解释原因?

is this a bug or can anyone explain why ?

推荐答案

答案是因为它是PHP。并且PHP不保证这种类型的语句(顺便说一下,C也没有)。

The answer is "because it's PHP". And PHP doesn't make guarantees about that type of statement (incidentally, neither does C).

是的,它可能被认为是错误的,但它是PHP。请参阅此非错误错误报告

Yes, it could be considered wrong, but it's PHP. See this "not a bug" bug report.

这篇关于PHP中的预增量和后增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆