PHP array_chunk() 函数
PHP 教程
· 2019-01-21 23:14:46
实例
把数组分割为带有两个元素的数组块:
<?php
$cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");
print_r(array_chunk($cars,2));
?>
$cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");
print_r(array_chunk($cars,2));
?>
定义和用法
array_chunk() 函数把一个数组分割为新的数组块。
语法
array_chunk(array,size,preserve_keys);
| 参数 | 描述 |
|---|---|
| array | 必需。规定要使用的数组。 |
| size | 必需。一个整数,规定每个新数组块包含多少个元素。 |
| preserve_key | 可选。可能的值:
|
技术细节
| 返回值: | 返回一个多维的数值数组,从 0 开始,每个维度都包含 size 元素。 |
|---|---|
| PHP 版本: | 4.2+ |
更多实例
实例 1
把数组分割为带有两个元素的数组块,并保留原始数组中的键名:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50");
print_r(array_chunk($age,2,true));
?>
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50");
print_r(array_chunk($age,2,true));
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Algorithms Illuminated (Part 2)
Tim Roughgarden / Soundlikeyourself Publishing, LLC / 2018-8-5 / USD 17.99
Algorithms are the heart and soul of computer science. Their applications range from network routing and computational genomics to public-key cryptography and machine learning. Studying algorithms can......一起来看看 《Algorithms Illuminated (Part 2)》 这本书的介绍吧!