在PHP中,for循环实际上是如何工作的?

编程入门 行业动态 更新时间:2024-10-27 06:24:38
本文介绍了在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循环实际上是如何工作的?

本文发布于:2023-11-02 14:04:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!