<?php
function dirSubdir($dirnfiles) {

$result = array();

$cdir = scandir($dirnfiles);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(“.”,”..”)))
{
if (is_dir($dirnfiles . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirSubdir($dirnfiles . DIRECTORY_SEPARATOR . $value);
}
else
{
$result[] = $value;
}
}
}

return $result;
}
?>

Output
Array
(
[subdir1] => Array
(
[0] => file1.php
[subsubdir] => Array
(
[0] => file2.php
[1] => file3.php
)
)
[subdir2] => Array
(
[0] => file4.php
}
)

Your Answer
Sign In
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.