是否可以在PHP中使用函數包含文件?我已經嘗試了一些東西,但該文件未包含在腳本中。PHP通過函數包含文件
我使用這個功能:
function run($entry_point){
if(!empty($entry_point)){
if(file_exists('assets/controllers/'.$entry_point.'.php'))
include 'assets/controllers/'.$entry_point.'.php';
else
include 'assets/controllers/home.php';
}
}
我的問題了,隨着這種功能的指標將不包括$entry_point
文件。
Index.php
代碼:
session_start();
run($_GET['location']);
謝謝!
'是否可以在PHP中使用函數包含文件?'是 – MonkeyZeus
「*如果包含在調用文件中的函數內發生,則包含在調用文件中的所有代碼將表現得好像它具有被定義在該函數中。*「[源](http://php.net/manual/en/function.include.php) – Frxstrem
好的,所以它有一個更乾淨的方式來做到這一點? –