Php array_chunk () function
Array_chunk
("= 4.2.0, PHP 5" in PHP 4)
Array_chunk-
Description
ArrayArray_chunk(Array input, int size [, bool preserve_keys])
Array_chunk ()Splits an array into multiple arrays. The number of units in each array isSizeDecide. The number of units in the last array may be smaller. The obtained array is a unit in a multi-dimensional array, and its index starts from scratch.
Set optional parametersPreserve_keysSetTRUE, So that PHP retains the original key name in the input array. If you specifyFALSE, Then each result array will be indexed with a new number starting from scratch. The default value isFALSE.
Parameters
Input
Array Operation
Size
Block Size
Preserve_keys
If set to TRUE, the key is retained. The default value is false.
Return Value
Returns an array of multi-level numeric indexes, from zero. Each layer contains size elements.
Error/exception
If the dimension is smaller than 1 E_WARNING, both throw and NULL are returned.
Instance
Example #1 array_chunk ()
The above example will output:
Array
(
[0] => Array
(
[0] =>
[1] => B
)
[1] => Array
(
[0] => c
[1] => d
)
[2] => Array
(
[0] => e
)
)
Array
(
[0] => Array
(
[0] =>
[1] => B
)
[1] => Array
(
[2] => c
[3] => d
)
[2] => Array
(
[4] => e
)
)