What is missing is to isolate the divs .row
of elements <span>
or if span appears independent of being % 4
then it should neither be within while
and % 4
should always be compared to 1 or 0 (as a suggestion of @Bacco to simplify we start comparing with % 4
zero):
<?php
$count = 0;
echo '<div class="row">', PHP_EOL;
while ($count <= 10) {
if ($count > 0 && $count % 4 === 0) {//A cada quatro deve fechar o .row e abrir novamente
echo '</div>', PHP_EOL, PHP_EOL, '<div class="row">', PHP_EOL;
}
echo '<span>', $count, '</span>', PHP_EOL;
$count++;
}
echo '</div>';
One important thing is that your code is not generating 10 items, but 11 because it starts at zero, so if the increment starts from 1 then the code would be simpler, since the quantity would be 10, is greater than 1:
<?php
$count = 1;
echo '<div class="row">', PHP_EOL;
while ($count <= 10) {
if ($count > 1 && $count % 4 === 1) {//A cada quatro deve fechar o .row e abrir novamente
echo '</div>', PHP_EOL, PHP_EOL, '<div class="row">', PHP_EOL;
}
echo '<span>', $count, '</span>', PHP_EOL;
$count++;
}
echo '</div>';