[英]PHP: How to include all files from all subdirectories from a directory
我想包含許多子目錄中的許多 PHP 文件。 但是如果我必須為每個子目錄使用 include 會很煩人。
例如:
include "./subdir1/*.php";
include "./subdir2/*.php";
include "./subdir3/*.php";
那么,有沒有一種方法可以只用一個include
語句來包含一個目錄中所有子目錄中的所有文件?
使用 php glob 函數。 下面的示例代碼
foreach (glob(document_root.'/class/*.php') as $filename) {
require_once($filename);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.