Skip to content

Instantly share code, notes, and snippets.

@abdeltiflouardi
Created November 28, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdeltiflouardi/b911a17ad9252985dcff1ed5ee08c44e to your computer and use it in GitHub Desktop.
Save abdeltiflouardi/b911a17ad9252985dcff1ed5ee08c44e to your computer and use it in GitHub Desktop.
Columns
<?php
$list = array(1,2,2,2,2,3,3,1,1,1,1,1,2,2,1,2,3,1,2,1,1,3);
$line = 1;
$ordered = array();
foreach ($list as $item) {
if (isset($ordered[$line]) && (array_sum($ordered[$line]) + $item) > 3) {
$line++;
}
$ordered[$line][] = $item;
}
var_dump($ordered);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment