Created
August 27, 2013 06:23
-
-
Save FrankM1/6350229 to your computer and use it in GitHub Desktop.
Grouping items in a foreach loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$i = 0; | |
$group = 0; | |
$group_by = 5; | |
while ($i < 19){ | |
$i++; | |
if ($group == 0) {//new group start | |
echo "<li>"; | |
} | |
echo "<div>item " . $i . "</div>"; | |
$group++; | |
if ($group == $group_by) {//end of group | |
echo "</li>\n"; | |
$group = 0; | |
$group_by = 6; | |
} | |
} | |
if ($group != 0) { echo "</li>"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: