Last active
February 5, 2019 13:24
-
-
Save LeoFeitosa/361e44c465ed085fab4329fc72621ee6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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