title: Scan files in a directory and sub-directory and store their path in array using php
body: <p>I want not scan all the files in a directory and its sub-directory. And get their path in an array. Like path to the file in the directory in array will be just </p>
  
  <blockquote>
    <p>path -> text.txt</p>
  </blockquote>
  
  <p>while the path to a file in sub-directory will be </p>
  
  <blockquote>
    <p>somedirectory/text.txt</p>
  </blockquote>
  
  <p>I am able to scan single directory, but it returns all the files and sub-directories without any ways to differentiate. </p>
  
  <pre><code>    if ($handle = opendir('fonts/')) {
      /* This is the correct way to loop over the directory. */
      while (false !== ($entry = readdir($handle))) {
          echo "$entry&lt;br/&gt;";
      }
  
  
      closedir($handle);
      }
  </code></pre>
  
  <p>What is the best way to get all the files in the directory and sub-directory with its path?</p>