Created
November 28, 2017 15:43
-
-
Save yavir-me/82560e426bb0309ae57b76ed0efa7afc to your computer and use it in GitHub Desktop.
nested files any deep to array
This file contains 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
function findFiles($directory, $extensions = array()) { | |
function glob_recursive($directory, &$directories = array()) { | |
foreach(glob($directory, GLOB_ONLYDIR | GLOB_NOSORT) as $folder) { | |
$directories[] = $folder; | |
glob_recursive("{$folder}/*", $directories); | |
} | |
} | |
glob_recursive($directory, $directories); | |
$files = array (); | |
foreach($directories as $directory) { | |
foreach($extensions as $extension) { | |
foreach(glob("{$directory}/*.{$extension}") as $file) { | |
$files[$extension][] = $file; | |
} | |
} | |
} | |
return $files; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment