Skip to content

Get all directories in PHP

I think this may be the fastest way to get a list of all the directories in a given folder/directory using PHP.

$directories = array_filter(glob('*'), 'is_dir');
Code language: PHP (php)

..and of course, you can also add a path to it if you need to:

$directories = array_filter(glob($myPath.'*'), 'is_dir');
Code language: PHP (php)

See also  PHP nl2br on one line
Tags:
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Mike Collier
11 years ago

just brilliant – took some finding on the web but works just fine for what i want for an automatic picture gallery where each event has its own folder of pics

1
0
Would love your thoughts, please comment.x
()
x