1

I want to include many PHP files from many subdirectories. But it will be very annoying if I have to use include for each subdirectory.

For example:

include "./subdir1/*.php";
include "./subdir2/*.php";
include "./subdir3/*.php";

So, is there a way to include all files from all subdirectories from a directory just with one include statement?

  • 1
    I'm sure you know how to configure your include path using php.ini. If you're writing an application ... and the application needs a million includes throughout your PHP code ... then there's probably something fundamentally wrong with your application's design :( – paulsm4 Sep 18 '20 at 04:06
  • Maybe this is what you want: [https://stackoverflow.com/questions/599670/how-to-include-all-php-files-from-a-directory](https://stackoverflow.com/questions/599670/how-to-include-all-php-files-from-a-directory) – Manish Pareek Sep 18 '20 at 06:01
  • Which method you are talking about? – Manish Pareek Sep 18 '20 at 08:01

1 Answers1

0

use php glob function. Example code below

foreach (glob(document_root.'/class/*.php') as $filename) {
    require_once($filename);
}