Created
November 20, 2015 11:01
-
-
Save Flard/328f3e3502d8eda4fed5 to your computer and use it in GitHub Desktop.
split items over columns
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
$numColumns = 3; | |
$itemsPerColumn = ceil(count($items)/$numColumns); | |
$keys = array_keys($items); | |
$result = array(); | |
for($i=0;$i<count($keys);$i++) { | |
$col = ($i % $numColumns); | |
$x = floor($i / $numColumns) + ($col * $itemsPerColumn); | |
$k = $keys[$x]; | |
$result[$k] = $items[$k]; | |
} | |
$items = $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment