如何破碎多维数组

时间:2013-10-26 18:54:23

标签: php arrays

我正试图破坏这个数组:

$name;
foreach ($childs as  $cval) {
  $name[] = $cval;
}

这就是我得到的:

Array
(
[0] => Array
    (
        [0] => Array
            (
                [pages_name] => services child 1
            )

        [1] => Array
            (
                [pages_name] => services child 2
            )

    )

[1] => Array
    (
        [0] => Array
            (
                [pages_name] => inner service child 1
            )

        [1] => Array
            (
                [pages_name] => inner service child 2
            )

    )

[2] => Array
    (
        [0] => Array
            (
                [pages_name] => gallery child 1
            )

        [1] => Array
            (
                [pages_name] => gallery child 2
            )

    )

)

我正在使用array_map这样做:

$arr = array_map(function($el){ return $el['pages_name']; }, $name);

$str = implode(',', $arr);

我收到了这个错误:

Undefined index: pages_name

1 个答案:

答案 0 :(得分:0)

你忘了深度,试试这个:

$arr = array_map(function($el){ return $el[0]['pages_name']; }, $name);