Answers:
break
完全结束一个循环,continue
只需捷径当前迭代并继续进行下一个迭代即可。
while ($foo) { <--------------------┐
continue; --- goes back here --┘
break; ----- jumps here ----┐
} |
<--------------------┘
这样使用:
while ($droid = searchDroids()) {
if ($droid != $theDroidYoureLookingFor) {
continue; // ..the search with the next droid
}
$foundDroidYoureLookingFor = true;
break; // ..off the search
}
break退出您所在的循环,继续立即从循环的下一个循环开始。
例:
$i = 10;
while (--$i)
{
if ($i == 8)
{
continue;
}
if ($i == 5)
{
break;
}
echo $i . "\n";
}
将输出:
9
7
6
作为记录:
请注意,在PHP 中,出于continue的目的,将switch语句视为循环结构。
continue 2
在这种情况下使用。
在循环结构中使用“继续”来跳过当前循环的其余部分,并在条件评估和下一次迭代的开始处继续执行。
'break'结束当前foreach,while,do-while或switch结构的执行。
break接受一个可选的数值参数,该参数告诉它要分解多少个嵌套的封闭结构。
查看以下链接:
http://www.php.net/manual/en/control-structures.break.php
http://www.php.net/manual/en/control-structures.continue.php
希望能帮助到你..
我在这里写的不一样。只是PHP手册中的变更日志记录。
更新日志以继续
Version Description
7.0.0 - continue outside of a loop or switch control structure is now detected at compile-time instead of run-time as before, and triggers an E_COMPILE_ERROR.
5.4.0 continue 0; is no longer valid. In previous versions it was interpreted the same as continue 1;.
5.4.0 Removed the ability to pass in variables (e.g., $num = 2; continue $num;) as the numerical argument.
休息的变更日志
Version Description
7.0.0 break outside of a loop or switch control structure is now detected at compile-time instead of run-time as before, and triggers an E_COMPILE_ERROR.
5.4.0 break 0; is no longer valid. In previous versions it was interpreted the same as break 1;.
5.4.0 Removed the ability to pass in variables (e.g., $num = 2; break $num;) as the numerical argument.