PHP目录/文件树结构-排序结果
我有一个脚本,可以创建文件夹、子文件夹和文件的树结构。每件事都很完美,但结果却没有分类 我想我需要将第一个循环添加到数组中,然后对其进行排序。但每次我的实验都失败了 请问,如何解决这个问题 非常感谢PHP目录/文件树结构-排序结果,php,arrays,sorting,Php,Arrays,Sorting,我有一个脚本,可以创建文件夹、子文件夹和文件的树结构。每件事都很完美,但结果却没有分类 我想我需要将第一个循环添加到数组中,然后对其进行排序。但每次我的实验都失败了 请问,如何解决这个问题 非常感谢 function createDir($path = '/home/www/mydomain/www/') { // I think I need an array here if ($handle = opendir($path)) { echo "
function createDir($path = '/home/www/mydomain/www/') {
// I think I need an array here
if ($handle = opendir($path)) {
echo "<ul>";
$queue = array();
while (false !== ($file = readdir($handle))) {
if (is_dir($path.$file) && $file != '.' && $file !='..') {
printSubDir($file, $path, $queue);
}
else if ($file != '.' && $file !='..') {
$queue[] = $file;
}
}
printQueue($queue, $path);
echo "</ul>";
}
}
function printQueue($queue, $path) {
asort($queue); // I tried this - it sorts only files and sub-folders but no root-folders
foreach ($queue as $file) {
printFile($file, $path);
}
}
function printFile($file, $path) {
echo "<li><a href=\"".$path.$file."\">$file</a></li>";
}
function printSubDir($dir, $path) {
echo "<li><span class=\"toggle\">$dir</span>";
createDir($path.$dir."/");
echo "</li>";
}
createDir();
函数createDir($path='/home/www/mydomain/www/){
//我想我需要一个数组
如果($handle=opendir($path)){
回声“”;
$queue=array();
while(false!=($file=readdir($handle))){
如果(is_dir($path.$file)&&&$file!='.&&&$file!=''..'){
printSubDir($file、$path、$queue);
}
如果($file!='.&&&$file!='..'),则为else{
$queue[]=$file;
}
}
printQueue($queue,$path);
回声“
”;
}
}
函数printQueue($queue,$path){
asort($queue);//我尝试了这个方法-它只对文件和子文件夹进行排序,而不对根文件夹进行排序
foreach($队列作为$文件){
printFile($file,$path);
}
}
函数printFile($file,$path){
回声“”;
}
函数printSubDir($dir,$path){
回声“$dir”;
createDir($path.$dir.“/”);
回声“ ”;
}
createDir();