title: How to access last file from folder in php
body: <p>I have a folder called images I want to access the last file From Folder and the naming of the images like AB00001.png and for the second image ImageName-AB00002 so on. Whenever it reaches ImageName-AB000010, in this case, getting the last image as ImageName-AB00009, but not ImageName-AB000010. </p>
  
  <pre><code>// scanning last file   
  $files = scandir('../images/', SCANDIR_SORT_DESCENDING);
  //for name of last file
  echo $newest_file = $files[0];
  // for substring after hyphen
  $lclStrAfterHyphen = substr($newest_file, strpos($newest_file, "-") + 1);
  // checking string length
  echo strlen($lclStrAfterHyphen);
  </code></pre>