Chunk () function [function] This function splits an array into multiple arrays, the size of the number of units in each array determines the number of units in the last array. the number of units in the array may be a few fewer, its index [scope of use] & gt; 4. 2... syntaxHighlighter. all ();
Chunk () function
[Function]
This function splits an array into multiple arrays,
The number of units in each array is determined by the size.
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.
Scope of use]
> = 4.2.0, php5
[Use]
Array array_chunk (array input, int size [, bool preserve_keys])
Input/required/split array
Size/required/Number of units in the array
Preserve_keys/optional/True reserve the original key name of the array,
The value of the False key is a numeric index starting from scratch. the default value is False.
[Example]
[Php]
$ Arr = array ("key1" => "val1", "key2" => "val2 ",
"Key3" => "val3", "key4" => "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
)
)
*/
Taken from zuodefeng's note