php - 一個取數組鍵值得問題
迷茫
迷茫 2017-05-16 12:58:11
0
2
475
Array
(
    [1] => Array
        (
            [id] => 1
            [access_id] => 1
            [name] => 统计报表
            [module] => manage
            [parent_id] => 0
            [icon] => fa-dashboard
            [type] => menu
            [sort] => 0
            [status] => 1
            [access_name] => 统计报表
            [controller] => dashboard
            [action] => index
        )

    [2] => Array
        (
            [id] => 2
            [access_id] => 
            [name] => 个人中心
            [module] => manage
            [parent_id] => 0
            [icon] => fa-male
            [type] => menu
            [sort] => 1
            [status] => 1
            [access_name] => 
            [controller] => 
            [action] => 
            [_child] => Array
                (
                    [3] => Array
                        (
                            [id] => 3
                            [access_id] => 
                            [name] => 修改个人信息
                            [module] => manage
                            [parent_id] => 2
                            [icon] => 
                            [type] => menu
                            [sort] => 0
                            [status] => 1
                            [access_name] => 
                            [controller] => 
                            [action] => 
                        )

                )

        )

    [4] => Array
        (
            [id] => 4
            [access_id] => 
            [name] => 广告管理
            [module] => manage
            [parent_id] => 0
            [icon] => fa-th
            [type] => menu
            [sort] => 2
            [status] => 1
            [access_name] => 
            [controller] => 
            [action] => 
            [_child] => Array
                (
                    [5] => Array
                        (
                            [id] => 5
                            [access_id] => 
                            [name] => 广告位管理
                            [module] => manage
                            [parent_id] => 4
                            [icon] => 
                            [type] => menu
                            [sort] => 0
                            [status] => 1
                            [access_name] => 
                            [controller] => 
                            [action] => 
                            [_child] => Array
                                (
                                    [8] => Array
                                        (
                                            [id] => 8
                                            [access_id] => 
                                            [name] => 添加广告位
                                            [module] => manage
                                            [parent_id] => 5
                                            [icon] => 
                                            [type] => menu
                                            [sort] => 1
                                            [status] => 1
                                            [access_name] => 
                                            [controller] => 
                                            [action] => 
                                        )

                                    [7] => Array
                                        (
                                            [id] => 7
                                            [access_id] => 
                                            [name] => 广告位列表
                                            [module] => manage
                                            [parent_id] => 5
                                            [icon] => 
                                            [type] => menu
                                            [sort] => 2
                                            [status] => 1
                                            [access_name] => 
                                            [controller] => 
                                            [action] => 
                                        )

                                )

                        )

                    [6] => Array
                        (
                            [id] => 6
                            [access_id] => 
                            [name] => 广告内容管理
                            [module] => manage
                            [parent_id] => 4
                            [icon] => 
                            [type] => menu
                            [sort] => 1
                            [status] => 1
                            [access_name] => 
                            [controller] => 
                            [action] => 
                            [_child] => Array
                                (
                                    [9] => Array
                                        (
                                            [id] => 9
                                            [access_id] => 
                                            [name] => 广告列表
                                            [module] => manage
                                            [parent_id] => 6
                                            [icon] => 
                                            [type] => menu
                                            [sort] => 0
                                            [status] => 1
                                            [access_name] => 
                                            [controller] => 
                                            [action] => 
                                        )

                                    [10] => Array
                                        (
                                            [id] => 10
                                            [access_id] => 
                                            [name] => 添加广告
                                            [module] => manage
                                            [parent_id] => 6
                                            [icon] => 
                                            [type] => menu
                                            [sort] => 1
                                            [status] => 1
                                            [access_name] => 
                                            [controller] => 
                                            [action] => 
                                        )

                                )

                        )

                )

        )

)

上面是個數組,包含的是選單的信息,可能有很多維,現在有一個問題是如果一個選單的id位8,也就是索引為
$arr[4]['_child'][5][ '_child'][8] 這個選單,我如何透過寫一個函數,傳回一個數組,該數組包含了所有的索引值,例如id為8的這個選單,返回[4,5,8]

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(2)
过去多啦不再A梦

_child數組裡面每個數組加上一個父選單id就可以了,然後透過索引一層一層讀,否則你得for 循環一個數組一個數組的判斷。效果太差

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板