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
The Book of CSS3
Peter Gasston / No Starch Press / 2011-5-13 / USD 34.95
CSS3 is the technology behind most of the eye-catching visuals on the Web today, but the official documentation can be dry and hard to follow. Luckily, The Book of CSS3 distills the heady technical la......一起来看看 《The Book of CSS3》 这本书的介绍吧!