Php-arrays function-chunk-to split an array into multiple arrays _php tutorial

Source: Internet
Author: User
Chunk () function
function
This function splits an array into multiple arrays,
Where the number of cells per array is determined by size
The number of cells in the last array may be few
The resulting array is a cell in a multidimensional array whose index starts at zero
"Scope of Use"
>=4.2.0, PHP5
Use
Array array_chunk (array input, int size [, bool Preserve_keys])
input/Required/segmented array
size/number of units required/split to array
preserve_keys/Optional/true retains the original key name of the array,
False key named zero-based numeric index, default = False
Example
[PHP]
$arr = Array ("Key1" = "Val1", "key2" = "Val2",
"Key3" = "Val3", "Key4" and "Val4");
Print_r (Array_chunk ($arr, 2));
Print_r (Array_chunk ($arr, 2, True));
Print_r (Array_chunk ($arr, 3));
/*
Array
(
[0] = = Array
(
[0] = Val1
[1] = Val2
)

[1] = = Array
(
[0] = Val3
[1] = Val4
)

)
Array
(
[0] = = Array
(
[Key1] = Val1
[Key2] = Val2
)

[1] = = Array
(
[Key3] = Val3
[Key4] = Val4
)

)
Array
(
[0] = = Array
(
[0] = Val1
[1] = Val2
[2] = Val3
)

[1] = = Array
(
[0] = Val4
)

)
*/

Excerpts from Zuodefeng's notes

http://www.bkjia.com/PHPjc/478197.html www.bkjia.com true http://www.bkjia.com/PHPjc/478197.html techarticle Chunk () function "function" This function splits an array into multiple arrays, where the number of cells per array has a size that determines the number of cells in the last array may be a few less ...

  • Related Article

    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.