0

我正在尝试内爆这个数组:

$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
4

1 回答 1

0

您忘记了深度级别,试试这个:

$arr = array_map(function($el){ return $el[0]['pages_name']; }, $name);
于 2013-10-26T19:08:06.283 回答