Jump to content

Recursive Function Array Build


peterg012

Recommended Posts

Hi,

 

I am trying to recursively build another array based on the one I get back from our CRM api.  The array I get back looks like this:

 

[1] => stdClass Object
        (
            [description] => Description Text
            [label] => Product
            [name] => Product
            [sobject] => KnowledgeArticleVersion
            [topCategories] => stdClass Object
                (
                    [childCategories] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [childCategories] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [childCategories] => Array
                                                        (
                                                            [0] => stdClass Object
                                                                (
                                                                    [label] => Apple
                                                                    [name] => Apple
                                                                )

                                                            [1] => stdClass Object
                                                                (
                                                                    [label] => Orange
                                                                    [name] => Orange
                                                                )

                                                            [2] => stdClass Object
                                                                (
                                                                    [label] => lemon
                                                                    [name] => lemon
                                                                )

                                                        )

                                                    [label] => Templates
                                                    [name] => Templates
                                                )

                                            [1] => stdClass Object
                                                (
                                                    [label] => Connector
                                                    [name] => Connector
                                                )

                                            [2] => stdClass Object
                                                (
                                                    [label] => AeroView
                                                    [name] => AeroView
                                                )

                                        )

                                    [label] => AeroWare
                                    [name] => AeroWare
                                )

                            [1] => stdClass Object
                                (
                                    [label] => BackOffice
                                    [name] => BackOffice
                                )

                            [2] => stdClass Object
                                (
                                    [label] => OutWare
                                    [name] => OutWare
                                )

                            [3] => stdClass Object
                                (
                                    [childCategories] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [label] => ERA
                                                    [name] => ERA
                                                )

                                            [1] => stdClass Object
                                                (
                                                    [label] => Kairos
                                                    [name] => Kairos
                                                )

                                        )

                                    [label] => InWare
                                    [name] => InWare
                                )

                        )

                    [label] => All
                    [name] => All
                )

        )

 

The child categories could be any level deep.  I would like put it in an array something like this:

Array
(
    [label] => Cat 1
    [level] => 0
    [children] => Array
        (
            [label] => Sub Cat 1
            [level] => 1
            [children] => Array
                (
                    [label] => Sub Sub Cat 1
                    [level] => 2
                )

        )

)

 

I have tried so many things but I just can't get it right.  Any assistance would be greatly appreciated.

 

Thanks

Peter

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.