Skip to content

Instantly share code, notes, and snippets.

@Flard
Created November 20, 2015 11:01
Show Gist options
  • Save Flard/328f3e3502d8eda4fed5 to your computer and use it in GitHub Desktop.
Save Flard/328f3e3502d8eda4fed5 to your computer and use it in GitHub Desktop.
split items over columns
$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