PHP 算术运算符 ++
为什么我只能加一而不能加其他值?
if(5++$var == 10){ ... }
显示解析错误
Why can I only increment by one and not by other value?
if(5++$var == 10){ ... }
shows a parse error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为此,请使用
+=
运算符。Use
+=
operator for this.您可以使用复合赋值运算符:
You can use the compound assignment operator:
您可以增加另一个值,语法只是不同:
5++
但是无效。++
运算符递增变量 并返回该变量的旧值。5
是一个常量;你无法修改它。您要么想要
5 + $var == 10
,或者更清楚:$var == 5
You can increment by another value, the syntax is just different:
5++
however is not valid. The++
operator increments a variable and returns the old value of that variable.5
is a constant; you can't modify it.You either want
5 + $var == 10
or, more clear:$var == 5
它显示解析错误,因为它是解析错误。 (正如它所写的,您试图对数值 5 进行后递增,等等。)
如果您试图检查 5 + $var 是否等于 10,请使用:
It's showing a parse error, because it's a parse error. (As it's written, you're attempting to post-increment the numerical value 5, etc.)
If you're attempting to check if 5 +
$var
is equal to 10 use:因为 ++ 是一个递增运算符,它精确地递增 1。
Because ++ is an increment operator that increments exactly by one.