Home > php教程 > php手册 > php将一维数组转换为每3个连续值组成的二维数组,维数二维数组

php将一维数组转换为每3个连续值组成的二维数组,维数二维数组

WBOY
Release: 2016-06-13 08:41:06
Original
1140 people have browsed it

php将一维数组转换为每3个连续值组成的二维数组,维数二维数组

本文实例讲述了php实现将一维数组转换为每3个连续值组成的二维数组。分享给大家供大家参考,具体如下:

<&#63;php
$aaa = array('aa','bb','cc','dd','ee','ff','gg','hh','ii');
for($i=0;$i<3;$i++)
{
  $bbb[] = array_slice($aaa, $i * 3 ,3);
}
print_r($bbb);
&#63;>

Copy after login

运行结果如下:

Array
(
  [0] => Array
    (
      [0] => aa
      [1] => bb
      [2] => cc
    )
  [1] => Array
    (
      [0] => dd
      [1] => ee
      [2] => ff
    )
  [2] => Array
    (
      [0] => gg
      [1] => hh
      [2] => ii
    )
)

Copy after login

关键代码:

$bbb[] = array_slice($aaa, $i * 3 ,3);
//3为3个一组,如果是2为2个一组
Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP数学运算技巧总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template