PHP 循环 - For 循环

循环执行代码块指定的次数,或者当指定的条件为真时循环执行代码块。

for 循环

for 循环用于您预先知道脚本需要运行的次数的情况。

语法

for (初始值; 条件; 增量)
{
要执行的代码;
}

输出:

The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

foreach 循环

foreach 循环用于遍历数组。

Syntax

foreach ($array as $value)
{
要执行代码;
}

输出:

one
two
three