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 ()