title: PHP RecursiveDirectoryIterator
body: <p>I want to do a RecursiveDirectoryIterator on a set of folders in a directory, say <code>./temp</code> and then list the files in each folder according to the name of the folder. </p>
  
  <p>For example I have the folders <code>A</code> and <code>B</code>. </p>
  
  <p>In A, I have a list of files say, <code>1.txt</code>, <code>2.php</code>, <code>2.pdf</code>, <code>3.doc</code>, <code>3.pdf</code>.</p>
  
  <p>In B, I have <code>1.pdf</code>, <code>1.jpg</code>, <code>2.png</code>.</p>
  
  <p>I want my results to be like this:</p>
  
  <pre><code>A =&gt; List of files in A
  B =&gt; List of files in B
  </code></pre>
  
  <p>How can this be done?</p>
  
  <pre><code>&lt;?php 
  $scan_it = new RecursiveDirectoryIterator("./temp"); 
  foreach(new RecursiveIteratorIterator($scan_it) as $file =&gt;$key) { 
      $filetypes = array("pdf"); 
      $filetype = pathinfo($file, PATHINFO_EXTENSION); 
      if (in_array(strtolower($filetype), $filetypes)) { 
          $dlist=basename($file); //sort 
  ?&gt; 
  &lt;ul&gt;
      &lt;li&gt;
          &lt;?php echo substr(dirname($file),11);?&gt;
      &lt;/li&gt; 
      &lt;li&gt;
          &lt;a href="&lt;?php echo $file;?&gt;"&gt;&lt;?php echo basename($file);?&gt;&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt; 
  &lt;?php 
      }} 
  ?&gt;
  </code></pre>