PHP循环遍历数组并拆分成单独的数组

时间:2010-10-21 09:47:51

标签: php multidimensional-array

嗨,我有这个亚马逊子类别的PHP数组,我想要做的是循环数组并分成3个单独的,

继承数组,需要拆分为3个数组$ request,以及$ subCats和最终变量$ Ancestors下的所有子进程。 $ subCats将包含所有[Children] [BrowseNode]。它让我发疯,我似乎无法正确循环。

任何想法的人。先进的干杯。

学家

Array
(
    [Request] => Array
        (
            [IsValid] => True
            [BrowseNodeLookupRequest] => Array
                (
                    [BrowseNodeId] => 66471031
                    [ResponseGroup] => Array
                        (
                            [0] => BrowseNodeInfo
                        )

                )

        )

    [BrowseNode] => Array
        (
            [BrowseNodeId] => 66471031
            [Name] => Beauty
            [Children] => Array
                (
                    [BrowseNode] => Array
                        (
                            [0] => Array
                                (
                                    [BrowseNodeId] => 118423031
                                    [Name] => Cosmetics
                                )

                            [1] => Array
                                (
                                    [BrowseNodeId] => 74006031
                                    [Name] => Cosmetics_hidden
                                )

                            [2] => Array
                                (
                                    [BrowseNodeId] => 118457031
                                    [Name] => Fragrances
                                )

                            [3] => Array
                                (
                                    [BrowseNodeId] => 66466031
                                    [Name] => Fragrances_hidden
                                )


                        )

                )

            [Ancestors] => Array
                (
                    [BrowseNode] => Array
                        (
                            [BrowseNodeId] => 66280031
                            [Name] => Categories
                            [IsCategoryRoot] => 1
                            [Ancestors] => Array
                                (
                                    [BrowseNode] => Array
                                        (
                                            [BrowseNodeId] => 65801031
                                            [Name] => Health & Beauty
                                        )

                                )

                        )

                )

        )

)

1 个答案:

答案 0 :(得分:1)

这应该这样做:

$request = your_main_array['request'];
$subCats = your_main_array['BrowseNode']['Children']['BrowseNode'];
$Ancestors = your_main_array['BrowseNode']['Ancestors']

['Children'] ['BrowseNode']和['Ancestors']位于主阵列下的[BrowseNode]数组中。