title: How to get filtered file name list using scandir in PHP?
body: <p>I would like to get all files that has '_img' and PDF type in a folder</p>
  
  <p>Instead of using </p>
  
  <pre><code>$fileArray = scandir($dir);
  foreach ($fileArray as $file) {
      if (preg_match("_img",$file) &amp;&amp; pathinfo($file, PATHINFO_EXTENSION) == 'pdf'){
          $filteredArray[] = $file;
      }
  }
  </code></pre>
  
  <p>Are there any short cut or it is the best way?  Thanks</p>