php多维数组仅用于数字键

时间:2013-11-15 16:18:07

标签: php multidimensional-array

我一直在努力解决几个小时内无法解决的问题。我想要一个特殊设计的多维数组。

这就是我所拥有的:

Array
(
[0] => Array
    (
        [0] => Array
            (
                [name] => bla
                [form_key] => bla
               )

        [1] => Array
            (
                [name] => bla
                [form_key] => bla
                [extra] => Array
                    (
                        [title_display] => inline
                        [private] => 0
                    )

            )

    )
    [1] => Array
    (
        [0] => Array
            (
                [name] => bla
                [form_key] => bla
            )

        [1] => Array
            (
                [name] => bla
                [form_key] => bla
                [extra] => Array
                    (
                        [title_display] => inline
                        [private] => 0
                    )

            )

    )

  )

但结果应该是:

Array
(
[0] => Array
      (
        [name] => bla
        [form_key] => bla
    )

[1] => Array
    (
        [name] => bla
        [form_key] => bla
        [extra] => Array
           (
             [title_display] => inline
             [private] => 0
           )
    )

[2] => Array
    (
        [name] => bla
        [form_key] => bla
        [extra] => Array
            (
                [title_display] => inline
                [private] => 0
            )

    )
    .
    .
    .

所以用语言说: 我想摆脱第一个数组并接收一个递增键,保留子数组中的关联键。

我正在尝试使用array_values和array_walk_recursive,但似乎我没有足够的PHP经验。

2 个答案:

答案 0 :(得分:0)

也许我错过了什么,但是面对面......

$newArray = array();
foreach ($array as $arr) {
  $newArray = array_merge($newArray,$arr);
}

答案 1 :(得分:0)

你试过这个吗?

$newArray = array();
foreach ($array as $items) {
    $newArray = array_merge($newArray, $items);
}