title: Finding latest file's name and modification time in PHP
body: <p>I search a director with <code>glob</code> function and get the matched files' list. Then by checking <code>filemtime</code> of the files I create a map. Then sort the map with respect to file dates. At last I get latest file's name and modification time. My code is like this. It works well for small directories, but it's slow for big directories. I wonder whether is there a faster/clever way?</p>
  
  <pre><code>$fileList = array();
  // $id = is the argument of this function
  $files = glob('myfolder'.DS.'someone'.$id.'*.txt');
  if (empty($files)) {
      return 0;
  }
  foreach ($files as $file) {
      $fileList[filemtime($file)] = $file;
  }
  
  if (sizeof($files) &gt; 1) {
      ksort($fileList);
  }
  
  $latestFilename = end($fileList);
  $fileLastModifDate = filemtime( $latestFilename );
  </code></pre>