Creating a parent-child object heirachy to display in tree view

I had a module that required display of a set of categories organised by id and parent id. To create a tree view I created a node object and small bit of code to render a HTML drop down form element.

Of course after creating this code I realised this information was in fact surplus to requirements and would potentially confuse users.

The code took too much love to delete so here it is for next time…