列出的文件我有点困惑如何我可以排序我的结果。我返回一个目录中的文件列表,并需要他们以某种方式排序...我如何排序由php
// Start directory
getDirectory('../gallery/photos');
function getDirectory($path = '.', $level = 0){
// Directories to ignore when listing output.
$ignore = array('.', '..');
// Open the directory to the handle $dh
$dh = @opendir($path);
// Loop through the directory
while(false !== ($file = readdir($dh))) {
// Change filename to display date
$displaydate= date('jS M Y', strtotime($file));
// Check that this file is not to be ignored
if(!in_array($file, $ignore)) {
// Indent spacing for better view
$spaces = str_repeat(' ', ($level * 5));
// Show directories only
if(is_dir("$path/$file")){
// Re-call this same function but on a new directory.
// this is what makes function recursive.
echo "$spaces<a href='$path/$file'>$displaydate</a><br />";
getDirectory("$path/$file", ($level+1));
}
}
}
// Close the directory handle
closedir($dh);
}
我在哪里应用排序功能?
感谢
之前,每个人都建议使用'水珠()'现在,请阅读[Bill Karwin](http://stackoverflow.com/users/20860/bill-karwin)的[将球体测试](http://www.phparch.com/2010/04/28/putting -glob-to-the-test) – Gordon 2010-11-14 23:29:20