我包括文件 inner.php
在 outer.php
, 我在 inner.php
中有一个条件我想停止执行inner.php
但不是整个脚本,即我想跳到 outer.php
的第一行列入inner.php
后,并且我不想将所有代码包装在 inner.php
中在 if 语句中。
有没有其他方法可以做到这一点?
最佳答案
只要做return;
或 return($value);
在 inner.php
文件的顶层。
If called from the global scope, then execution of the current script file is ended. If the current script file was
include()ed
orrequire()ed
, then control is passed back to the calling file. Furthermore, if the current script file wasinclude()ed
, then the value given toreturn()
will be returned as the value of theinclude()
call.
关于php - 跳过 PHP 中其余(包含的)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6136254/