title: sort folder content by date/time using PHP?
body: <p>I'm trying to sort the content of a folder by their date/time.
  my code bellow gets all the content properly but they are all over the place and they are not sorted by date/time.</p>
  
  <p>my code:</p>
  
  <pre><code>if(isset($_GET['dir'])) {
      $directory = $_GET['dir'];
  
      $dir = "".$directory."";
      $files = scandir($dir);
      //rsort($files);
  
      $TIMEANDATE = date("F d Y h:i A");
  
      foreach ($files as $file) {
          $date = filemtime(''.$dir.'/'.$file.'');
          if ($file != '.' &amp;&amp; $file != '..') {
              array_multisort(array_map('filemtime', $file), SORT_ASC, $file); 
              $filesize = human_filesize(filesize(''.$dir.'/'.$file.''));
              $all_doc .= "&lt;tr&gt;
                              &lt;td&gt;&lt;input  type='checkbox'/&gt;&lt;/td&gt;
                              &lt;td&gt;".$fileExt."&amp;nbsp;&lt;a class='defaults'  href='" . $dir ."/". $file . "'&gt;". $file ."&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href=''&gt;&lt;i title='Move' class='fa fa-refresh'&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;
                                  &lt;a href='folder.php?del=" . $dir ."/". $file . "'&gt;&lt;i title='Delete' class='fa fa-times'&gt;&lt;/i&gt;&lt;/a&gt;
                              &lt;/td&gt;           
                              &lt;td&gt;Status&lt;/td&gt;
                              &lt;td&gt;".date('F d Y h:i A', $date)."&lt;/td&gt;
                              &lt;td&gt;".$filesize."&lt;/td&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;";
             $i++;
          }
  
      }
  }
  </code></pre>
  
  <p>I tried this line of code but it doesn't sort them:</p>
  
  <pre><code>array_multisort(array_map('filemtime', $file), SORT_ASC, $file); 
  </code></pre>
  
  <p>could someone please advise on this?</p>
  
  <p>any help would be appreciated.</p>
  
  <p>Edit: this question has no answer in other posts because the code is clearly different and I cannot change my code to reflect other people's codes on other posts. so I need to work with my own code. </p>