0
我有單獨的php文件。我有使用由包括這些文件就像梳理包括php文件
/include '1.php';
/include '2.php';
/include '3.php';
現在,我想我可以用它們來此3文件合併到一個PHP file.How一個主文件,因爲我的主碼有3個條件,如條件1使用文件1.php條件2使用文件2.php等 thanx
我有單獨的php文件。我有使用由包括這些文件就像梳理包括php文件
/include '1.php';
/include '2.php';
/include '3.php';
現在,我想我可以用它們來此3文件合併到一個PHP file.How一個主文件,因爲我的主碼有3個條件,如條件1使用文件1.php條件2使用文件2.php等 thanx
嗨,你可以寫你的代碼,這樣
<?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');
?>
良好的工作!
如果要將文件組合成一個文件,但仍使用主文件的條件,只需包含來自包含文件的代碼在您用來選擇包含文件的相同條件下。如果您有:
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 2和3中的文件是否需要添加到主文件的開頭。 – 2012-03-20 19:52:48