PHP Array_chunk () function
Definitions and usage
A series of array_chunk () functions splits into a new array.
Grammar
Array_chunk (Array,size,preserve_key)
Parameter Description array Required. Specifies the array to use size Required. Specifies how many elements the each new array would contain Preserve_key Optional. Possible values:true-preserves The keys from the original Array.false-default. does not preserve the keys from the original array.
Look at the instance.
<?php
$a =array ("a" => "Cat", "B" => "Dog", "C" => "horse", "D" => "Cow");
Print_r ($a , 2)); The result of
.
Array (
[0] => Array ([0] => Cat [1] => Dog)
[1] => Array ([0] => horse [1] => Cow)
Look at an example.
<?php
$a =array ("a" => "Cat", "B" => "Dog", "C" => " Horse "," D "=>" Cow ");
Print_r (Array_chunk ($a, 2,true));
?
Output is as follows.
Array (
[0] => Array ([a] => Cat [b] => Dog)
[1] => Array ([C] => horse [d] => Cow)
)