PHP 讀取檔案時間排序取值
阿新 • • 發佈:2018-12-12
$newest = true; $dir = '/usr/leyangjun/local/etc/nginx/servers/'; $dh = opendir($dir); if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($fileName = readdir($dh)) !== false){ if ($fileName != "." && $fileName != "..") { $fileNamePath = $dir.$fileName; $fileArr[$fileNamePath] = date("Y-m-d H:i:s",filemtime($fileNamePath)); } } arsort($fileArr);//倒序 if ($newest) {//取最新一條 $needKey = count($fileArr) - 1; $fileArr[] = $fileArr[$needKey]; } closedir($dh); } }