如何包含()目录中的所有 PHP 文件?

2022-01-25 00:00:00 include php

我可以在 PHP 中包含一个脚本目录吗?

In PHP can I include a directory of scripts?

即而不是:

include('classes/Class1.php');
include('classes/Class2.php');

有没有类似的东西:

include('classes/*');

似乎找不到为特定类包含大约 10 个子类的集合的好方法.

Couldn't seem to find a good way of including a collection of about 10 sub-classes for a particular class.

推荐答案

foreach (glob("classes/*.php") as $filename)
{
    include $filename;
}

相关文章