我有这部分代码:
<?php
$pathLen = 0;
function myScanDir($dir, $level, $rootLen)
{
global $pathLen;
if ($handle = opendir($dir)) {
$allFiles = array();
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir . "/" . $entry))
{
$allFiles[] = "D: " . $dir . "/" . $entry;
}
else
{
$allFiles[] = "F: " . $dir . "/" . $entry;
}
}
}
closedir($handle);
natsort($allFiles);
foreach($allFiles as $value)
{
$displayName = substr($value, $rootLen + 4);
$fileName = substr($value, 3);
$linkName = str_replace(" ", "%20", substr($value, $pathLen + 3));
if (is_dir($fileName)) {
echo '<ul>'. $linkName ;
myScanDir($fileName, $level + 1, strlen($fileName));
echo "</ul>";
} else {
echo "<li><a href=\"" . $linkName . "\" style=\"text-decoration:none;\">" . $displayName . "</a></li>";
}
}
}
}
?>
<?php
$root = 'file';
$pathLen = strlen($root);
myScanDir($root, 0, strlen($root));
?>
我想将此函数的输出返回给array。
但是我不知道该怎么办。
顶级功能的结果是: