How do I"catch" every 7th item in a list?
<p>I'm using <a href="http://php.net/manual/en/class.directoryiterator.php" rel="nofollow">DirectoryIterator</a> to list files. In this scenario my dir contains 19 files.</p>

<p>I need to create a list which wraps 7 files into a <code>&lt;div&gt;</code>.</p>

<p>I must be tired, because I'm not able to do this simple task.</p>

<p><strong>My code is updated to reflect suggestions below</strong>:</p>

<pre><code>$i = 0;
echo '&lt;div class="first_div"&gt;';

foreach ($dir as $fileinfo) {
  if ($fileinfo-&gt;isFile()) {
    if(($i % 7 == 0) &amp;&amp; ($i &gt; 0) )
      echo '&lt;/div&gt;&lt;div&gt;';

    echo 'My file';
    $i++;
  }
}
echo '&lt;/div&gt;';
</code></pre>

<p>Any help appreaciated.</p>
