PHP: Divide and Split an Array into Chunks (Sections) or Several Sub-arrays

A big array is awkward. To divide the big array and split it into smaller sub-arrays or children arrays by size, you can use the PHP function array_chunk():

$sections = array_chunk(array('k', 'l', 'm', 'n', 'o'), 2);

To slice $sections into smaller arrays by the size of 2, and $sections will look like this:

Array
(
    [0] => Array
        (
            [0] => k
            [1] => l
        )

    [1] => Array
        (
            [0] => m
            [1] => n
        )

    [2] => Array
        (
            [0] => o
        )

)
Scroll to Top