Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created May 6, 2014 13:39
Show Gist options
  • Save DWboutin/8cea4c0d538e771f798b to your computer and use it in GitHub Desktop.
Save DWboutin/8cea4c0d538e771f798b to your computer and use it in GitHub Desktop.
Directory to array
<?php
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value){
if (!in_array($value,array(".",".."))){
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