Skip to content

Instantly share code, notes, and snippets.

@tomodutch
Created March 17, 2014 14:16
Show Gist options
  • Save tomodutch/9599973 to your computer and use it in GitHub Desktop.
Save tomodutch/9599973 to your computer and use it in GitHub Desktop.
<?php
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $file)
if (!$file->isDir() && $file->getFilename() !== '.' && $file->getFilename() !== '..') {
$key = pathinfo($file->getPathName(), PATHINFO_DIRNAME);
if (!isset($data[$key]))
$data[$key] = [$file->getFilename()];
else
$data[$key][] = $file->getFilename();
}
return $data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment