Created
May 21, 2021 04:35
-
-
Save NachoToast/368907e68985486f380d5ca201ebc065 to your computer and use it in GitHub Desktop.
Create an array of folders in a directory, recursively.
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 | |
function add_folders($root) { | |
$local_folders_array = array(); | |
foreach (glob("$root/*", GLOB_ONLYDIR) as $folder) { | |
array_push($local_folders_array, ['foldername' => $folder]); | |
$arr2 = add_folders($folder); | |
if (count($arr2) > 0) foreach($arr2 as $subfolder) array_push($local_folders_array, ['foldername' => $subfolder['foldername']]); | |
} | |
return $local_folders_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment