在PHP中包含文件而不包含其他内容?

在PHP中包含文件而不包含其他内容?,php,Php,我目前正在将一个新的php文件以 if (...) { ... } include("old_file"); 有没有一种方法可以在条件中包含此新文件,而不更改外部零件/包括其他零件? e、 g 您可以调用exit停止执行,或者在包含的文件内调用return,在包含文件外也可以正常工作 if (...) { Code that should be executed if condition is set. include("new_file"); exit();

我目前正在将一个新的php文件以

if (...) {
   ... 
}

include("old_file");
有没有一种方法可以在条件中包含此新文件,而不更改外部零件/包括其他零件? e、 g

您可以调用exit停止执行,或者在包含的文件内调用return,在包含文件外也可以正常工作

if (...) {
   Code that should be executed if condition is set. 
   include("new_file"); 

   exit(); // terminates execution
}

// Code that should not be executed if condition is set.
include("old_file"); 
...
如果{ //设置条件时应执行的代码。 包括新文件;
return;//您可以在$new\u文件中设置一个变量,并检查它是否在old\u文件中设置,如果设置了,就不要在那里解析任何数据。old\u文件之后的内容如何,从…那里判断,那里有一些内容,OP只想在包含新\u文件时跳过包含。不,这是答案,我不知道返回和退出!
if (...) {
   Code that should be executed if condition is set. 
   include("new_file"); 

   exit(); // terminates execution
}

// Code that should not be executed if condition is set.
include("old_file"); 
...