Ari*_*Ari 9 php loops nested continue break
我有以下循环,continue当内循环内的检查符合条件时,我想要while循环.我在这里找到了一个解决方案(我在下面的例子中应用了),但它适用于c#.
$continue = false;
while($something) {
foreach($array as $value) {
if($ok) {
$continue = true;
break;
// continue the while loop
}
foreach($value as $val) {
if($ok) {
$continue = true;
break 2;
// continue the while loop
}
}
}
if($continue == true) {
continue;
}
}
Run Code Online (Sandbox Code Playgroud)
continue当内部循环被break淘汰时,PHP是否有自己的主循环方式?
Ari*_*Ari 18
在阅读了这个问题的评论(被其作者删除)并进行了一些研究后,我发现还有参数continue就像break.我们可以添加数字,continue所以:
while($something) {
foreach($array as $value) {
if($ok) {
continue 2;
// continue the while loop
}
foreach($value as $val) {
if($ok) {
continue 3;
// continue the while loop
}
}
}
}
Run Code Online (Sandbox Code Playgroud)