Skip to content

Instantly share code, notes, and snippets.

@larchanka
Last active May 6, 2019 11:24
Show Gist options
  • Save larchanka/ec037a7b8a299bc8860d05f3728c3b2a to your computer and use it in GitHub Desktop.
Save larchanka/ec037a7b8a299bc8860d05f3728c3b2a to your computer and use it in GitHub Desktop.
Function to scan directory and return array of files
<?php
function dirToArray($dir) {
$ignoredPath = array(
".",
"..",
".htaccess"
);
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value) {
if (!in_array($value, $ignoredPath)) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
} else {
$result[] = $value;
}
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment