views:

115

answers:

2

Basically i received an API SOAP response of a list of categories in an class format as in array kind of way with CatID, name, parentID, level.

What is the best way to turn this into an array of breadcrumbs for each CatID.

I want to try reduce the number of operation as the array will be created on the fly to populate a drop down menu and there are over a 1000 categories

I apologise in advance for my poor terminology and thank you for any help

A: 

i solved it by converting it into an array and applying a tree alogorithim to each element

i know its not very efficent

rosh3000
A: 

Input using print($response) was

[CategoryArray] => stdClass Object
    (
        [Category] => Array
            (
                [0] => stdClass Object
                    (
                        [BestOfferEnabled] => 1
                        [AutoPayEnabled] => 1
                        [CategoryID] => 353
                        [CategoryLevel] => 1
                        [CategoryName] => Antiques
                        [CategoryParentID] => 353
                    )

                [1] => stdClass Object
                    (
                        [BestOfferEnabled] => 1
                        [AutoPayEnabled] => 1
                        [CategoryID] => 550
                        [CategoryLevel] => 1
                        [CategoryName] => Art
                        [CategoryParentID] => 550
                        [LSD] => 1
                    )

                [2] => stdClass Object
                    (
                        [BestOfferEnabled] => 1
                        [AutoPayEnabled] => 1
                        [CategoryID] => 2984
                        [CategoryLevel] => 1
                        [CategoryName] => Baby
                        [CategoryParentID] => 2984
                    )

                [3] => stdClass Object
                    (
                        [BestOfferEnabled] => 1
                        [AutoPayEnabled] => 1
                        [CategoryID] => 267
                        [CategoryLevel] => 1
                        [CategoryName] => Books, Comics & Magazines
                        [CategoryParentID] => 267
                    )
                    ... ...             
                )

    )

the output wanted was

array(array(CategoryID = '353', breadCrumb = 'Antiques', parentID = '353'), 
      array(CategoryID = '4334', breadCrumb = 'Antiques->Chairs', parentID= '353'),
      ...
)

thank you Gumbo

rosh3000