Php array_chunk () function

Source: Internet
Author: User

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
)

)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.