Easy Tutorial
❮ Func Math Floor Pdostatement Getcolumnmeta ❯

PHP array_chunk() Function

Complete PHP Array Reference Manual

Example

Split an array into chunks with two elements each:


Definition and Usage

The array_chunk() function splits an array into new array chunks.


Syntax

Parameter Description
array Required. Specifies the array to use.
size Required. An integer that specifies how many elements each new array chunk should contain.
preserve_key Optional. Possible values: true - Preserves the keys from the original array.<br> false - Default. Each new array chunk uses a zero-based index.

Technical Details

Return Value: Returns a multidimensional numeric array, starting from 0, with each dimension containing size elements.
PHP Version: 4.2+
--- ---

More Examples

Example 1

Split an array into chunks with two elements each, while preserving the keys from the original array:


❮ Func Math Floor Pdostatement Getcolumnmeta ❯