繁体   English   中英

PHP:如何包含目录中所有子目录中的所有文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM