Php – How to include() all PHP files from a directory

includePHP

In PHP can I include a directory of scripts?

i.e. Instead of:

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

is there something like:

include('classes/*');

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

Best Answer

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