Converting a Joined Resultset Into a Hierarchy

I needed nested resultsets in some projects. I’ve seen a lot of StackOverflow chatter which essentially pointed people towards Doctrine or Propel ORMs, which was overkill when you didn’t want mapping or even model classes.

I built a very small function that will transform joined results into a hierarchy. This avoids using heavy ORMs if you just need this small feature. It’s 74 lines of code and really easy to use. Since it’s open source, feel free to improve it.

You’d give it a statement like this:

and it will produce something this:

Optionally, you can replace stdClass by your own classes with just a single parameter.

It’s on my GitHub. All the documentation is there.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">