PHP:使用某种'break'回到循环的开始?

问题描述:

嗨,我有一个循环,我想知道,如果有,你可以跳回到循环的开始,而忽略了其他代码在循环PHP:使用某种'break'回到循环的开始?

示例的命令:

for ($index = 0; $index < 10; $index++) 
{ 
    if ($index == 6) 
     that command to go the start of the loop 

    echo "$index, "; 
} 

应该输出

1,2,3,4,5,7,8,9 并跳过六

排序相同的结果作为

for ($index = 0; $index < 10; $index++) 
{ 
    if ($index != 6) 
     echo "$index, "; 
} 

是否有这样的命令?

感谢, matthy

+2

`continue`:PHP手册是你的朋友。 – 2011-01-08 02:24:38

关键字使用的是continue

for ($index = 0; $index < 10; $index++) 
{ 
    if ($index == 6) 
     continue; // Skips everything below it and jumps to next iteration 

    echo "$index, "; 
} 

顺便说一句,以获得所需输出的for行应阅读,而不是(除非你错过了零):

for ($index = 1; $index < 10; $index++) 

是的,continue前进到下一次迭代。