我有单独的php文件。我有一个我使用的主文件包括这些文件,如
/include '1.php';
/include '2.php';
/ include '3.php';
现在我想将这3个文件合并到一个php文件中。如何使用它们,因为在我的主代码中有3个条件,如条件1使用文件1.php条件2使用文件2.php等等 感谢名单
答案 0 :(得分:2)
如果要将文件合并为一个文件,但仍然使用主文件的条件,只需将include文件中的代码包含在用于选择包含文件的相同条件中。如果你有:
if(A){
include "1.php";
}
if(B){
include "2.php";
}
if(C){
include "3.php";
}
改为使用:
if(A){
//contents of 1.php here
}
if(B){
//contents of 2.php here
}
if(C){
//contents of 3.php here
}
答案 1 :(得分:1)
您好,您可以这样编写代码
<?php
if(condition1) include('file1.php');
else if(condition2) include('file2.php');
else include('file3.php');
?>
你可以写这个
<?php
if(condition1) include('file1.php');
if(condition2) include('file2.php');
if(condition3) include('file3.php');
?>
干得好!