title: Sort files by date added Laravel PHP
body: <p>So now I need to display an array of images from a directory in date added order (now it shows the files by name). The function wasn't written by me as I don't understand PHP. I tried a number of solutions here, but without knowing the syntax one could'n do much.</p>
  
  <p>So how to sort files here?</p>
  
  <pre><code>public function getPhotos($nav, $page=false)
  {
      if($page==false){
          $dir = 'img/'.$nav;
      }
      else{
          $dir = 'img/'.$nav.'/'.$page;           
      }
      $files = FILE::allFiles($dir);
      foreach($files as $file){
          if(pathinfo($file, PATHINFO_EXTENSION)=='png' or pathinfo($file, PATHINFO_EXTENSION)=='gif' or pathinfo($file, PATHINFO_EXTENSION)=='jpg'){
              $result[] = (string)explode("$page\\",$file)[1];
          }
      }
      echo $json_response = json_encode($result);
  }
  </code></pre>