I’m using DirectoryIterator to list files. In this scenario my dir contains 19 files.
I need to create a list which wraps 7 files into a <div>.
I must be tired, because I’m not able to do this simple task.
My code is updated to reflect suggestions below:
$i = 0;
echo '<div class="first_div">';
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
if(($i % 7 == 0) && ($i > 0) )
echo '</div><div>';
echo 'My file';
$i++;
}
}
echo '</div>';
Any help appreaciated.
Try using the mod operator (%) to determine if the current file number is the 7th one:
(Code is untested but should work)
EDIT : Used an independent counter for $i, since the index seemed to start at 2 and not 0 as expected.