我可以像这样遍历一个目录和一个子文件夹
$directoryArray = scandir('../portalFolders/');
foreach($directoryArray as $directory){
$listString .='
<li class="closed"><span class="folder">'.$directory.'</span>';
$subDirectoryArray = scandir('../portalFolders/'.$directory);
$howManyFolders = $subDirectoryArray -> count();
if($howManyFolders > 0){
$listString .= '<ul>';
foreach($subDirectoryArray as $subDirectory){
$listString .= '<li class="closed"><span class="folder">'.$subDirectory.'</span><li>';
}
$listString .= '</ul>';
}
else{
$listString .= '</li>';
}
}
如何在不嵌套另一个子目录的情况下使其搜索/循环遍历子目录的所有子目录foreach()
?这样,我可以通过 FTP 添加任意数量的文件夹/子文件夹,而不必在代码中加深嵌套。