0

I search a Solution to get all values from [BrowseNodeId] and [Name] from all [Ancestors] in a new array called categories. I think it must be a recursive loop, but how?

Array (
    [BrowseNodeId] => 343505011
    [Name] => Kinderzimmer
    [Ancestors] => Array (
        [BrowseNode] => Array (
            [BrowseNodeId] => 3517801
            [Name] => Möbel
            [Ancestors] => Array (
                [BrowseNode] => Array (
                    [BrowseNodeId] => 3312261
                    [Name] => Möbel & Wohnaccessoires
                    [Ancestors] => Array (
                        [BrowseNode] => Array (
                            [BrowseNodeId] => 3169011
                            [Name] => Kategorien
                            [IsCategoryRoot] => 1
                            [Ancestors] => Array (
                                [BrowseNode] => Array (
                                    [BrowseNodeId] => 3167641
                                    [Name] => Küche & Haushalt
                                )
                            )
                        )
                    )
                )
            )
        )
    )
) 
2
  • Can you include what you have tried and what did/din't work as expected? Commented Jan 14, 2015 at 21:25
  • Similar: stackoverflow.com/questions/1319903/… Commented Jan 14, 2015 at 21:28

1 Answer 1

1

Try something like this

function getAllInfo($inputArray, $outputArray = array()) {
    $outputArray[] = array(
        'BrowseNodeId' => $inputArray['BrowseNodeId'],
        'Name' => $inputArray['Name']
    );
    if(isset($inputArray['Ancestors']['BrowseNode'])) {     
        return getAllInfo($inputArray['Ancestors']['BrowseNode'], $outputArray);
    }
    return $outputArray;    
}

See it in action here (with the test array you provided): http://3v4l.org/jd7hY

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

Comments

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.