【发布时间】:2018-08-18 18:39:48
【问题描述】:
为什么 while 循环显示 2 个不同的输出?
$a=1;
while ($a++ <4) {
echo $a. "<br>";
} // output is 2 3 4 but (4 is not less than 4 )
$a=1;
while (++$a <4) {
echo $a. "<br>";
} // output is 2 3
请问,谁能详细解释一下区别? 在 $a++ 中它显示输出 2 3 4 但 4 在 while 条件下不小于 4 那么为什么它显示 4 不满足条件?
【问题讨论】:
-
你的答案在这里都解释了为什么这样的工作:stackoverflow.com/a/9901848/7657988
-
在此处阅读前自增和后自增运算符的效果:php.net/manual/en/language.operators.increment.php
-
@Rohan 是前自增和后自增运算符的作用。
-
谢谢大家
标签: php while-loop