This question is about Kohana framework. I’m new to it.
Using foreach() I want to display some data. Everything is fine, but I want to group that data 4 items in a row so it looks like:
1st 2nd 3rd 4th
5th 6th 7th 8th
9th 10th 11th 12th
....
That’s why I have to add <div> every 4th time.
How do you make it? Do you use a simple counter and check if its mod is zero? Is there a special Kohana function to check the number of the current $item within foreach() if it is the first, the second or the n-th… item ?
<?foreach ($items as $item): ?>
//add <div> tag for 1st, 4th, 7th, etc item
//do something
//add closing </div> tag for 1st, 4th, 7th, etc item
<? endforeach; ?>
Using the
foreachconstruct specifying the array key via$key => $item, you can test if$key % 4 == 0(or maybe$key % 4 == 3in your case) to close the open<div>.The templating syntax hurts my eyes. Here’s proper PHP:
Given the following input: