Skip to content

Instantly share code, notes, and snippets.

@LeoFeitosa
Last active February 5, 2019 13:24
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 LeoFeitosa/361e44c465ed085fab4329fc72621ee6 to your computer and use it in GitHub Desktop.
Save LeoFeitosa/361e44c465ed085fab4329fc72621ee6 to your computer and use it in GitHub Desktop.
<?php
$array = array('um',
'dois',
'tres',
'quatro',
'cinco',
'seis',
'sete',
'oito',
'nove',
'dez');
$tamanho = 4;
$output = array_chunk($array, $tamanho);
if(count($array) % $tamanho) {
$sobras = array_pop($output);
$ultimo = array_pop($output);
array_push($output, array_merge($ultimo, $sobras));
}
echo '<pre>';
print_r($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment