Skip to content

Instantly share code, notes, and snippets.

@laurynas
Created August 12, 2010 13:51
Show Gist options
  • Save laurynas/520993 to your computer and use it in GitHub Desktop.
Save laurynas/520993 to your computer and use it in GitHub Desktop.
PHP: array_to_rows
<?php
function array_to_rows($array, $cols, $complete = true)
{
$rows = array_chunk($array, $cols);
$last = count($rows) - 1;
if (!$complete || $last < 0)
return $rows;
$n = count($rows[$last]);
for ($i=$n; $n < $cols; $n++)
array_push($rows[$last], null);
return $rows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment