查找数字命名文件中最大的文件

Avatar of Chris Coyier
Chris Coyier
$latest = getNewest("/path/to/folder/*_bla.xml");

function getNewest($xmlfile){
   foreach (glob($xmlfile) as $filename) {
       $c = explode('_', basename($filename));
       $files[$c[0]] = $filename;
   }
   ksort($files, SORT_NUMERIC);
   $latest = array_pop($files);
   if (file_exists($latest)){
       return $latest;
   }
   return false;
}

在一个文件夹中,文件命名为
1_bla.xml
2_bla.xml

34_bla.xml

该函数返回具有最大数字的文件
$latest = “/path/to/folder/34_bla.xml”;