PHP Array_chunk ()

Source: Internet
Author: User

Definition and usage

The Array_chunk () function splits an array into a new array block.

The length of each array is determined by the parameter size.

Optional parameter Preserve_key is a Boolean value that specifies whether the new array uses the same key (index) as the original array, or the key (index) to reassign. The default is to reassign the new key.

Grammar
1 array_chunk (Array,size,preserve_key)
Parameters Describe
Array Necessary. Specifies the array to use.
Size Necessary. Specifies the length of each new array.
Preserve_key

Optional. Possible values:

  • True-preserves the key names in the original array.
  • False-Default. Each result array uses a new zero-based index of the array.

Example 1
<?php$a = Array ("A" = "a", "B" = "B", "C" = "C", "D" = "D", "e" = "E");p Rint_r (Array_chunk ($a, 2));? >

Output:

Array ([    0] = = Array ([0] = A [1] = B)    [1] = = Array ([0] = = C [1] + D)    [2] + = Array ( [0] = (E)))

  

Example 2
<?php$a = Array ("A" = "a", "B" = "B", "C" = "C", "D" = "D", "e" = "E");p Rint_r (Array_chunk ($a, 2,true));? >

Output:

Array (    [0] = = Array ([a] + a [b] = = b)    [1] = = Array ([c] + = c [d] + D)    [2] = = Array ([E] = e))

  

PHP Array_chunk ()

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.