php array chunk function

Usage

<?php

$array = [1,2,3,4,5,6,7,8,9];

foreach(array_chunk($array) as $part) {
    print_r($part);
}

and you’ll get output chunked by given chunk size:

Array
(
    [0] => 1
    [1] => 2
)
Array
(
    [0] => 3
    [1] => 4
)
Array
(
    [0] => 5
    [1] => 6
)
Array
(
    [0] => 7
    [1] => 8
)
Array
(
    [0] => 9
)

thanks @200PercentDev for pointing this out.

comments powered by Disqus