在PHP中,for循環(huán)的語法如下:
for (initialization; condition; increment) {
// code to be executed
}
示例:
for ($i = 0; $i < 5; $i++) {
echo "The number is: $i <br>";
}
在上面的示例中,初始化計數(shù)器變量為0,當計數(shù)器變量小于5時,繼續(xù)循環(huán)并輸出計數(shù)器變量的值,然后每次循環(huán)結(jié)束后將計數(shù)器變量加1。循環(huán)會執(zhí)行5次,輸出如下:
The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 4