How to display line by line using foreach?

There should be something like pratta.ru/catalogue
displays row by row, for 4 elements in the string. And the rows are numbered row1, row2, row3 and so on
July 9th 19 at 13:09
4 answers
July 9th 19 at 13:11
Solution
Start with the fact that there adaptiven, and 4 in the row - conditional.

And the output for 4 is very simple. The remainder of the division is 0.

// close the div with the elements and open a new one.
<?if(i % 4 == 0) { ?>
 
<?} ?>
July 9th 19 at 13:13
Solution
Such things are done through CSS.
mean to assign something like col-sm-3? but then there will be one row - Kendrick_Schu commented on July 9th 19 at 13:16
: no, inline-block or flex. - Allene_Crona78 commented on July 9th 19 at 13:19
July 9th 19 at 13:15
Solution
If you do like the example, then you no need to bother at the expense of output elements for 4 in a row. Print all the elements one by one.
foreach ($items as $key => $item) {
 echo "<div>{$item}</div>";
}


Later in CSS you set the width of the container and the width/height div. All.
July 9th 19 at 13:17
//$arr is "flat" list of elements
foreach ($arr as $i=>$item){
$row=1+floor($i/4);
$col=($i+1)%4;

 if ($col==1) echo '<div>'.$item;
 else if ($col<4) echo $item;
 else echo $item."</div>\r\n";
}

Find more questions by tags PHP