<?php
$i = 0;
foreach ($categories as $category) {
if (($i % 4) === 0) {
echo "<div class='row'>";
}
echo '<div class="col-lg-3 col-md-3"></div>';
if (($i % 4) === 3) {
echo "</div>";
}
$i++;
}
?>
Ps, If it $categoriesis an uncertified array, that is array('a', 'b', 'c'), then you can get rid of i = 0;and i++;and change foreach toforeach ($categories as $i => $category) {
zerkms, % ( Modulo), 0 , 12, reset 0. , . , .
Modulo four 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, etc