PHP:将多维数组转换为单个数组

时间:2018-04-30 05:37:04

标签: php multidimensional-array

我有一个像下面这样的数组:我想把它变成单数组格式。

Array
  (
    [0] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
        [4] => 10
    )

[1] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
    )
 )

希望获得如下输出。

[0] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
        [4] => 10
    )

[1] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
        [3] => 3
    )

我如何实现我的首选格式?任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

使用foreach(),您可以轻松地循环播放

<?php

$array = [
        [0, 1, 2, 3, 10],
        [0, 1, 2, 3]
    ];

foreach ($array as $smallArray)
{
    var_dump($smallArray);
}

Try it out yourself here