Given list of PHP files in a directory and the task is to include all files from a directory. In order to include all PHP files from directory at once need a foreach-loop.
Example: This example contains four PHP files (file1.php, file2.php, file3.php, file4.php) in a directory. Create one file named as main.php which contains PHP code to include files.
Create file1.php in folder ‘myGeeks’:
Create file2.php in folder ‘myGeeks’:
Create file3.php in folder ‘myGeeks’:
Create file4.php in folder ‘myGeeks’:
Create main.php outside folder:
Run on Windows platform:
- Folder myGeeks which contains all files:
- Folder htdocs contains main.php file:
- Run on Browser:
Run on Ubuntu platform:
- Folder ‘Desktop/folder’ which contains all files:
- Folder ‘Desktop’ contains main.php file:
- Run on Terminal:
- How to include Functions from other files in Node.js ?
- How to count files in a directory using PHP?
- How to see the changes in whole directory/folder containing many sass files ?
- Check if directory contains files using python
- How to keep compiled files in a separate directory ?
- How to display all files in a directory using Node.js ?
- How to get names of all the subfolders and files present in a directory using PHP?
- Java program to merge contents of all the files in a directory
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?
- Copy the entire contents of a directory to another directory in PHP
- PHP | (Include and Require)
- How to include one CSS file in another?
- Include v/s Extend in Ruby
- AngularJS | ng-include Directive
- @include vs @extend in SASS
- SASS | @mixin and @include
- What is the best way to include CSS file? Why use @import?
- Why does AngularJS include an empty option in select ?
- How to Zip a directory in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.