在PHP中,for循环实际上是如何工作的? [英] How does for loop works actually in php?
本文介绍了在PHP中,for循环实际上是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是php的新手,我已经了解了php中的所有其他循环,但是问题是我无法理解for循环的工作原理,例如: 这是代码;
I'm a newbie to php and I've understood all other loops in php but the question is I cannot understand how the for loops works for ex: Here is the code;
$a = 0;
$b = 0;
for ($i=0; $i < 5; $i++) {
$a += 10;
$b += 5;
}
echo("At the end of the loop a=$a and b=$b");
当我执行此脚本时,a = 50和b = 25的值!
When I execute this script the value of a = 50 and b = 25!
是否将a值与i的增量值相乘?例如10 * 5 = 50.
Is it multiplying the a value with i's increment value? like 10 * 5 = 50.
推荐答案
您的循环运行了五次.每次循环时,您将$a
的值加10.这样做五次即可得到50.
Your loop runs five times. Each time through the loop you add 10 to the value of $a
. Doing that five times gives you 50.
这篇关于在PHP中,for循环实际上是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文