What’s left is to isolate the Ivds .row
of the elements <span>
or if span appears independent of % 4
then he shouldn’t even be inside the while
and the % 4
should always be compared to 1 or 0 (as a suggestion from @Bacco to simplify we will start comparing with the % 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 the code would be simpler, because the amount would be 10, it will be necessary to check if it 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>';
As an experiment, I made a version of a single line. In practice, this should not be done in order not to be unreadable at the time of maintenance. http://ideone.com/xlbAAc
– Bacco