Home>Article>Backend Development> PHP algorithm to split array without array_chunk()_PHP tutorial

PHP algorithm to split array without array_chunk()_PHP tutorial

WBOY
WBOY Original
2016-07-13 10:17:24 1554browse

PHP algorithm to split array without array_chunk()

Use PHP to write an algorithm to split the array without using array_chunk(); the algorithm is as follows.

 $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));


www.bkjia.com true http: //www.bkjia.com/PHPjc/892831.html TechArticle php algorithm to split arrays without array_chunk() Use PHP to write an algorithm to split arrays without array_chunk(); the algorithm is as follows shown. $value) { // Whether this value exists if (! isset($newarray[$i]...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn