Created
December 28, 2011 18:18
-
-
Save trevorsheridan/1528988 to your computer and use it in GitHub Desktop.
Iterator that takes a single dimensional array as input and produces a multidimensional array of groups of three
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 | |
$lc = sizeof($list); | |
for ($i = 0; $i < ( ($lc % 3 == 0) ? $lc : ($lc - ($lc % 3) + 3) ); $i = $i + 3) { // This loop defines the group you're in, $i will always be divisible by 3. | |
for ($si = 0; $si < ( ($i + 3 < $lc) ? 3 : ($lc - $i) ); $si++) // Determine which item is next in this group. | |
$a[] = list[$i + $si]; | |
$groups[] = $a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment