Definition
The array_chunk() function splits an array into chunks of arrays.
Syntax
array_chunk(array, size, preserve_key)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies the array to use |
size |
Required. An integer that specifies the size of each chunk. |
preserve_key |
Optional. Values: true - Preserves the keys; false - Default. Reindex the chunk numerically |
Example
<?php
// Indexed Array
$cities = array("USA" => "New York", "Germany" => "Berlin", "Japan" => "Tokyo", "Turkey" => "Istanbul");
print_r(array_chunk($cities,2,true));