从PHP中的多维数组获取一些值

时间:2018-06-26 11:57:22

标签: php arrays multidimensional-array

我有一个4到5级的多维数组,我想从中提取一些特定的值

这是我的阵列...

$tree = [
        "grandfather" => "Allah Bakhsh",
        "father" => [
            "Father_1" => "Akram",
                "child Akram" => [
                    "Child_1" => "Faisal",
                        "subchild faisal" => [
                            "subchild Faisal 1" => "Usama",
                            "subchild Faisal 2" => "Abdul Wali"
                        ],
                    "Child_2" => "Ali",
                        "subchild Ali" => [
                        "subchild" => "No Child"
                        ],
                ],


            "Father_2" => "Ashraf",
                "child Ashraf" => [
                    "Child_1" => "Sajid",
                        "subchild Sajid" => [
                            "subchild Sajid 1" => "Abdullah",
                            "subchild Sajid 2" => "Taha",
                            "subchild Sajid 3" => "Moosa"
                        ],
                    "Child_2" => "Majid",
                        "subchild Majid" => "No Child",


                ],

            "Father_3" => "Khalid",
                "child Khalid" => "No Child"
        ],
    ];

我想获取所有的值

"Father_2" => "Ashraf",

我多次尝试使用foreach循环,但无法完成。

请提出一些建议...

0 个答案:

没有答案