如何将数组从三维展平为二维?

时间:2014-07-19 18:23:53

标签: php arrays multidimensional-array flatten

我如何压扁以下数组。我想摆脱0和1,只需要0-5作为键。我顺便使用php。

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [id] => 182
                )

            [1] => Array
                (
                    [id] => 183
                )

            [2] => Array
                (
                    [id] => 185
                )

            [3] => Array
                (
                    [id] => 184
                )

            [4] => Array
                (
                    [id] => 186
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [id] => 171
                )

        )

)

1 个答案:

答案 0 :(得分:0)

$flatArray = array();

foreach ($array as $l1Array){
  foreach ($l1Array as $k => $v){
    $flatArray[]=$v;
  } 
}