从php中的多级数组中获取数组名称

时间:2016-07-04 01:43:34

标签: php arrays wordpress

我如何从数组中获取WP_Widget_Archives

这是我的阵列:

$control = Array
(
    [name] => Archives
    [id] => archives-6
    [callback] => Array
        (
            [0] => WP_Widget_Archives Object
                (
                    [id_base] => archives
                    [name] => Archives
                    [widget_options] => Array
                        (
                            [classname] => widget_archive
                            [description] => A monthly archive of your site’s Posts.
                        )

                    [control_options] => Array
                        (
                            [id_base] => archives
                        )

                    [number] => 8
                    [id] => archives-8
                    [updated] => 
                    [option_name] => widget_archives
                )

            [1] => form_callback
        )

    [params] => Array
        (
            [0] => Array
                (
                    [number] => 6
                )

        )

    [width] => 250
    [height] => 200
    [id_base] => archives
)

我试过这段代码

`echo '<pre>'; print_r(array_keys($control['callback'])); echo '</pre>';`

但是我得到了这样的结果

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

我觉得结果会像这样

$result = Array
(
    [0] => WP_Widget_Archives Object
    [1] => form_callback
)

所以我可以为$result[0]撰写WP_Widget_Archives,请帮助我并感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

可能你误解了array_key函数。它会给你数组的键而不是值。在你的情况下,你需要一个对象'WP_Widget_Archives'的值,所以你可以直接使用$ control ['callback'] [0]。