Home  >  Article  >  Backend Development  >  PHP converts a one-dimensional array into a two-dimensional array consisting of every 3 consecutive values

PHP converts a one-dimensional array into a two-dimensional array consisting of every 3 consecutive values

高洛峰
高洛峰Original
2017-02-06 15:54:251217browse

The example of this article describes the PHP implementation of converting a one-dimensional array into a two-dimensional array composed of three consecutive values. Share it with everyone for your reference, the details are as follows:

The running results are as follows:

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

Key code:

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

I hope this article will be helpful to everyone in PHP programming.

For more articles related to PHP converting a one-dimensional array into a two-dimensional array composed of three consecutive values, please pay attention to the PHP Chinese website!

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