定义
array_chunk — 将一个数组分割成多个
描述
array_chunk ( array $array , int $size [, bool $preserve_keys = FALSE ] ) : array
将 array 数组按 size 指定的大小分割成多个数组,最后一个长度可能小于size.
preserve_keys,是否保留键名,默认是false.
返回一个多维索引数组,其中每一维包含 size 大小的数组.
示例
<?php $input_array = array('a', 'b', 'c', 'd', 'e'); print_r(array_chunk($input_array, 2)); print_r(array_chunk($input_array, 2, true)); ?>
将输出:
Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [0] => c [1] => d ) [2] => Array ( [0] => e ) ) Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [2] => c [3] => d ) [2] => Array ( [4] => e ) )
来源:https://www.cnblogs.com/jiaoran/p/12637617.html