PHP Array function-array_chunk ()

Source: Internet
Author: User

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

The number of cells in each of these arrays is determined by the size parameter. The number of cells in the last array may
will be less than a size.

An optional parameter, Preserve_key, is a Boolean value that specifies whether the elements of the new array have the and primitive numbers
The same set of keys (for associative arrays) or new number keys starting at 0 (for indexed arrays)
。 The default is to assign a new key.

Array_chunk (Array,size,preserve_key);

Array: Required. Specifies the array to use.

Size: Required. Specifies how many elements each new array contains.

Preserve_key: Optional. Possible value: True-retains the key name from the original array. false-
Recognize. Each result array uses a new zero-based index of the array.

<?php
$a=Array(' a ' = ' = ' Cat ', ' b ' + = ' Dog ', ' c ' = ' Horse ', ' d ' = ' Cow ');
Print_r(Array_chunk($a, 2));
?>

Output: Array ([0] = = Array ([0] = = Cat [1] = Dog) [1] = = Array
([0] = Horse [1] = Cow))

<?php
$a=Array(' a ' = ' = ' Cat ', ' b ' + = ' Dog ', ' c ' = ' Horse ', ' d ' = ' Cow ');
Print_r(Array_chunk($a, 2,true));
?>

Output: Array ([0] = = Array ([a] + = Cat [b] = Dog) [1] = = Array
([c] = Horse [d] = Cow))

PHP Array function-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.