Created
May 6, 2014 13:39
-
-
Save DWboutin/8cea4c0d538e771f798b to your computer and use it in GitHub Desktop.
Directory to array
This file contains hidden or 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
<?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