我使用此代碼列出目錄中的所有文件:$d = dir($FolderToPlay);while (($file = $d->read()) !== false){......}$d->close();但是,結果不按數字順序排列。我該如何修復它?
2 回答

素胚勾勒不出你
TA貢獻1827條經驗 獲得超9個贊
獲取所有文件名的列表,然后您可以使用排序功能。
$d = glob("$FolderToPlay/*");
natsort($d);
foreach ($d as $file) {
...
}

catspeake
TA貢獻1111條經驗 獲得超0個贊
列出目錄中所有文件的最簡單方法是使用scandir() 函數。你可以這樣使用它:
//Create a variable that contains all your files
$root = scandir($dir);
//Do something with each value, like push them into an array, do regex etc.
foreach($root as $value){
//...
}
- 2 回答
- 0 關注
- 167 瀏覽
添加回答
舉報
0/150
提交
取消