Use the PHP write algorithm to split the array without Array_chunk (); the algorithm is as follows.
<?php//$array Array//$size number of each array//whether each array element is default key value function Array_chunk_list ($array, $size, $preserve _keys = False) { reset ($array); $i = 0; foreach ($array as $key + $value) { //whether there is this value if (! isset ($newarray [$i])) { $newarray [$i] = array (); if (count ($newarray [$i]) < $size) {//The question to be judged first if ($preserve _keys = = False) { $newarray [$i] = $value;
} else { $newarray [$i] [$key] = $value; } } else { $i + +; if ($preserve _keys = = False) { $newarray [$i] = $value; } else { $newarray [$i] [$key] = $value; } } } return $newarray;} $array =array (1,2,3,4,5,6,7); Print_r (Array_chunk_list ($array, 2,true));
PHP algorithm split array, without Array_chunk ()