PHP 读取文件时间排序取值

$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);
    }
}

你可能感兴趣的:(PHP)