Skip to content

Instantly share code, notes, and snippets.

@medeirosinacio
Last active June 24, 2021 21:00
Show Gist options
  • Save medeirosinacio/1ecaf9268cbfc99d892c4d7c1c738611 to your computer and use it in GitHub Desktop.
Save medeirosinacio/1ecaf9268cbfc99d892c4d7c1c738611 to your computer and use it in GitHub Desktop.
List true files and true directories inside the specified path in PHP
/**
* List true files and true directories inside the specified path
* @param $directory
* @return array
*/
function true_scandir($directory)
{
$result = [];
$cdir = scandir($directory);
foreach ($cdir as $key => $value) {
if (!in_array($value, array(".", ".."))) {
if (is_dir($directory . DIRECTORY_SEPARATOR . $value)) {
$result[$value] = true_scandir($directory . 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