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]
<Span style = "font-size: 16px;"> <? 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
)
)
*/</Span>
Taken from zuodefeng's note