Home > Backend Development > PHP Tutorial > PHP converts a one-dimensional array into a two-dimensional array composed of every 3 consecutive values, the number of dimensions of the two-dimensional array_PHP tutorial

PHP converts a one-dimensional array into a two-dimensional array composed of every 3 consecutive values, the number of dimensions of the two-dimensional array_PHP tutorial

WBOY
Release: 2016-07-12 08:53:40
Original
826 people have browsed it

php converts a one-dimensional array into a two-dimensional array composed of three consecutive values. A two-dimensional array composed of every 3 consecutive values. Share it with everyone for your reference, the details are as follows:

The running results are as follows:

<&#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

Key code:

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

Readers who are interested in more PHP-related content can check out the special topics on this site: "Complete PHP Array Operation Skills", "Summary of PHP Sorting Algorithms", "Summary of PHP Common Traversal Algorithms and Techniques", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "PHP Mathematical Operation Skills Summary", "php Regular Expression Usage Summary", "PHP Operations and Operator Usage Summary", "php String Usage Summary" 》and《Summary of common database operation skills in php》

$bbb[] = array_slice($aaa, $i * 3 ,3);
//3为3个一组,如果是2为2个一组
Copy after login
I hope this article will be helpful to everyone in PHP programming.

http://www.bkjia.com/PHPjc/1123794.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1123794.htmlTechArticlephp converts a one-dimensional array into a two-dimensional array composed of every 3 consecutive values, the number of dimensions of the two-dimensional array This article The example describes how PHP converts a one-dimensional array into a two-dimensional array composed of three consecutive values. Points...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template