Created
August 3, 2021 13:35
-
-
Save w-jerome/218f953f02855289b25671b0f419b693 to your computer and use it in GitHub Desktop.
PHP - Get folders from path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'folder'; | |
$denies = array('..', '.'); | |
$entries = array_diff(scandir($path), $denies); | |
foreach ($entries as $key => $file_or_folder) { | |
if (!is_dir($path . DIRECTORY_SEPARATOR . $file_or_folder)) { | |
unset($entries[$key]); | |
} | |
} | |
$folders = array_values($entries); | |
var_dump($folders); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment