Skip to content

Instantly share code, notes, and snippets.

@anthonyholmes
Last active December 30, 2015 02:59
Show Gist options
  • Save anthonyholmes/7766759 to your computer and use it in GitHub Desktop.
Save anthonyholmes/7766759 to your computer and use it in GitHub Desktop.
Recursive Directory Tree into array
<?php
$dir = __DIR__;
function gather($dir){
$tree = [];
$allFilesAndDirs = glob($dir."/*");
foreach($allFilesAndDirs as $f){
if(is_dir($f)){
$tree[] = [$f, gather($f)];
}
else{
$tree[] = $f;
}
}
return $tree;
}
$tree = gather($dir);
var_dump($tree);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment