Split an array into chunks
To split an array into smaller chunks or smaller sized arrays, we use array_chunk() function of PHP. This will return arrays of several smaller sizes and each array's index number will start with zero unless you want to use the preserve_keys parameter to preserve the original index numbers from the input array used. The syntax is:
array_chunk ( array input, int size [, bool preserve_keys] )
Using the above function in an example:
PHP Code:
<?
$my_array = array("One", "Two", "Three", "Four");
$split_array = array_chunk($my_array, 2);
print_r($split_array);
//Output: Array (
// [0] => Array (
// [0] => One
// [1] => Two )
// [1] => Array (
// [0] => Three
// [1] => Four )
// )
?>