Search code examples
phpinclude

How to include() all PHP files from a directory?


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.


Solution

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