Iterating through hierarchical data

Any quicker way to iterate through this kind of nested data?

I’m trying to echo comment values in a hierarchical way as they shown in the pic in HTML list tags. I’ve tried Collection::nest but didn’t work for me.

I’d recommend looking into recursive methods (like in a custom View Helper)

Does that mean there aren’t ready CakePHP methods for such a nested object/array data?

Not built in because they heavily depend on what object structure you have.

But there are plugins like which help you output tree structures

1 Like

I’ve checked the plugin, but it includes many other helpers along the tree helper which could add up size to the project.

I’ve been trying RecursiveIteratorIterator & RecursiveArrayIterator classes to solve the problem but stuck in the middle due to not able to find detailed explanation on those classes.

Many thanks.