- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get all subdirectories of a given directory in PHP
To get the subdirectories present in a directory, the below lines of code can be used −
Example
<?php $all_sub_dirs = array_filter(glob('*.*'), 'is_dir'); print_r($all_sub_dirs); ?>
Output
This will produce the following output. The glob function is used to get all the subdirectories of a specific directory−
Array ( [0] => demo.csv [1] => mark.php [2] => contact.txt [3] => source.txt )
To get only the directories, the below lines of code can be used−
Example
<?php $all_dirs = glob($somePath . '/*' , GLOB_ONLYDIR); print_r($all_dirs); ?>
Output
This will produce the following output. The glob function is used by specifying that only directories need to be extracted−
Array ( [0] => example [1] => exam [2] => log )
Advertisements