因此,我有一个包含在 index.php
中的 sidebar.php。在某种情况下,我想让sidebar.php
停止运行,所以我想到把exit
放在sidebar.php
中,但实际上是退出了它下面的所有代码意味着 include('sidebar.php');
在 index.php
中的所有代码也将被跳过。有没有办法让 exit
只跳过 sidebar.php
中的代码?
最佳答案
只需使用 return;
请注意,以这种方式实际上可以将某些内容返回给调用脚本。
如果你的父脚本有 $somevar = include("myscript.php");
然后在 myscript.php 你说... return true;
你将在 $somevar
关于php - 有没有办法只退出包含的 php 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726710/