PHP array_chunk() Function
Complete PHP Array Reference Manual
Example
Split an array into chunks of two elements:
Run Example »
Definition and Usage
The array_chunk() function splits an array into new chunks.
Syntax
array_chunk(
array
,
size
,
preserve_keys
);
| Parameters | Description |
|---|---|
| array | Required. Specifies the array to use. |
| size | Required. An integer specifying how many elements each new chunk contains. |
| preserve_key | Optional. Possible values:
|
Technical Details
| Return Value: | Returns a multidimensional numeric array, starting at 0, where each dimension contains size . |
|---|---|
| PHP Version: | 4.2+ |
More examples
Example 1
Split an array into chunks of two elements and preserve the original keys:
"35","Ben"=>"37","Joe"=>"43","Harry"=>"50"); print_r(array_chunk($age,2,true)); ?>Run Example »
Complete PHP Array Reference Manual