Skip to content

Instantly share code, notes, and snippets.

@NachoToast
Created May 21, 2021 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NachoToast/368907e68985486f380d5ca201ebc065 to your computer and use it in GitHub Desktop.
Save NachoToast/368907e68985486f380d5ca201ebc065 to your computer and use it in GitHub Desktop.
Create an array of folders in a directory, recursively.
<?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