我需要一个函数,用于根据修改日期按反向顺序对文件列表进行排序。
这是我想到的
function display_content($dir,$ext){
$f = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($folder = readdir($dh)) !== false) {
if (preg_match("/\s*$ext$/", $folder)) {
$fullpath = "$dir/$folder";
$mtime = filemtime ($fullpath);
$ff = array($mtime => $fullpath);
$f = array_merge($f, $ff);
}
}
rsort($f, SORT_NUMERIC);
while (list($key, $val) = each($f)) {
$fcontents = file($val, "r");
while (list($key, $val) = each($fcontents))
echo "$val\n";
}
}
}
closedir($dh);
}
这样调用它
display_content("folder","extension");