Function definition:
array_chunk() function can split an array into new array chunks and return a multi-dimensional numerical array, starting from 0, each Dimensions all contain size elements.
(Recommended tutorial: php graphic tutorial)
Syntax:
array_chunk(array,size,preserve_keys);
php video tutorial)
Code example:Now we need to split the array into An array block of two elements, retaining the key names from the original array.<?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50"); print_r(array_chunk($age,2,true)); ?>
Array ( [0] => Array ( [Peter] => 35 [Ben] => 37 ) [1] => Array ( [Joe] => 43 [Harry] => 50 ) )
The above is the detailed content of Introduction to the usage of php array_chunk function (example). For more information, please follow other related articles on the PHP Chinese website!