title: find and list all specific extension in directories and sub-directories in php
body: <p>below code only list files in directories and does not search sub-directories:</p>
  
  <pre><code>&lt;?php
  //path to directory to scan. i have included a wildcard for a sub directory
  $directory = "/var/www/*/";
  
  //get all image files with a .jpg extension.
  $images = glob("" . $directory . "*.jpg");
  
  $imgs = '';
  // create array
  foreach($images as $image){ $imgs[] = "$image"; }
  
  //shuffle array
  shuffle($imgs);
  
  //select first 20 images in randomized array
  $imgs = array_slice($imgs, 0, 1000);
  
  //display images
  foreach ($imgs as $img) {
      echo $img . '&lt;br&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>but How can list all specific extension (for example *.jpg) in all directories and </p>
  
  <p>sub directories of a path by using PHP?</p>