Use PHP to write an algorithm to split the array without using array_chunk(); the algorithm is as follows.
<?php //$array 数组 //$size 每个数组的个数 //每个数组元素是否默认键值 function array_chunk_list($array, $size, $preserve_keys = false) { reset($array); $i = 0; foreach ($array as $key => $value) { // 是否存在这个值 if (! isset($newarray[$i])) { $newarray[$i] = array(); } if (count($newarray[$i]) < $size) { // 先判断的问题 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));