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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 08:53:40852browse

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;>

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
    )
)

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个一组
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...
Statement:
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