title: scandir() to sort by date modified
body: <p>I'm trying to make <code>scandir();</code> function go beyond its written limits, I need more than the alpha sorting it currently supports. I need to sort the <code>scandir();</code> results to be sorted by modification date. </p>
  
  <p>I've tried a few solutions I found here and some other solutions from different websites, but none worked for me, so I think it's reasonable for me to post here.</p>
  
  <p>What I've tried so far is this:</p>
  
  <pre><code>function scan_dir($dir)
  {
      $files_array = scandir($dir);
      $img_array   = array();
      $img_dsort   = array();
      $final_array = array();
  
      foreach($files_array as $file)
      {
          if(($file != ".") &amp;&amp; ($file != "..") &amp;&amp; ($file != ".svn") &amp;&amp; ($file != ".htaccess"))
          {
              $img_array[] = $file;
              $img_dsort[] = filemtime($dir . '/' . $file);   
          }
      }
  
      $merge_arrays = array_combine($img_dsort, $img_array);
      krsort($merge_arrays);
  
      foreach($merge_arrays as $key =&gt; $value)
      {
          $final_array[] = $value;    
      }
  
      return (is_array($final_array)) ? $final_array : false;
  }
  </code></pre>
  
  <p>But, this doesn't seem to work for me, it returns 3 results only, but it should return 16 results, because there are 16 images in the folder.</p>