我面临这样的情况((从php docs中提取))
在循环中包含的文件中使用continue语句将产生错误.例如:
// main.php
for($x=0;$x<10;$x++)
{ include('recycled.php'); }
// recycled.php
if($x==5)
continue;
else
print $x;
Run Code Online (Sandbox Code Playgroud)
它应该打印"012346789"没有五,但它会产生一个错误:
Cannot break/continue 1 level in etc.
Run Code Online (Sandbox Code Playgroud)
有一个解决方案吗??,我的意思是我需要以这种方式"处理"recycled.php,其中使用continue语句不会导致此错误,请记住这是易于理解的示例代码,在实际情况下我需要找到一种方法来继续main.php文件的循环..
您可以使用return而不是continue在page2.php:
if ($x == 5) {
return;
}
print $x;
Run Code Online (Sandbox Code Playgroud)
如果包含或需要当前脚本文件,则将控制权传递回调用文件.此外,如果包含当前脚本文件,则返回的值将作为include调用的值返回.
PHP:回归