-1
我使用這個功能列出文件夾中的所有文件和子文件夾PHP列表中的所有文件和按字母順序排序
function printAll($dirName){
$dirs=array($dirName);
$files=array();
while($dir=array_pop($dirs)){
$handle=opendir($dir);
while($file=readdir($handle)){
if($file!='.' && $file!='..'){
$dest=$dir.'/'.$file;
if(is_file($dest)){
$files[]=$file;
echo $file;
}else{
$dirs[]=$dest;
}
}
}//end of 1st while
}//end of 2nd while
return $files;
}//end of function
printAll(getcwd());
但是,有沒有辦法,我可以按字母順序排序的文件名列表?
使用[SCANDIR()](HTTP://www.php。 net/manual/en/function.scandir.php)它給了你一個排序選項 –
作爲一個旁註,如果你已經正確縮進你的代碼,你就不需要像'// end of while'這樣的評論...... – fvu
選項將用asort($ files)對數組$ files []進行排序 – bestprogrammerintheworld