Skip to content

Instantly share code, notes, and snippets.

@pietvanzoen
Created July 8, 2013 17:10
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 pietvanzoen/5950632 to your computer and use it in GitHub Desktop.
Save pietvanzoen/5950632 to your computer and use it in GitHub Desktop.
Array_group :: Divide an array into groups. #php
<?php
/**
* Returns an array of arrays.
*
* $array - an array to be divided
* $groups - number of groups to divide the array into
*/
function array_group($array, $groups)
{
$items_in_each_group = ceil(count($array)/$groups);
return array_chunk($array, $items_in_each_group);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment