0

Hi I have this PHP array of Amazon Sub Categories what I am trying to do is loop through the array and split into 3 seperate ones,

Heres the Array, and needs to be split into 3 arrays $request, and all the children under it $subCats and final variable $Ancestors. The $subCats will contain all the [Children][BrowseNode]. Its driving me mad I cant seem to loop through correctly.

Any thoughts people. Cheers in advanced.

J.

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
                                        )

                                )

                        )

                )

        )

)
2
  • What code arey you using? Where are you stuck? Commented Oct 21, 2010 at 9:49
  • PHP mate, I can loop through the array but I dont know how to get to the [Children][BrowseNodes] level so I can drag out the sub cat names. Commented Oct 21, 2010 at 10:01

1 Answer 1

1

This should do it:

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

['Children']['BrowseNode'] and ['Ancestors'] are in a [BrowseNode] Array under you main array.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers araf! Nice one so simple! Been looking at the code to long!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.