News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Daniel Cousineau's Blog:
Displaying N-Deep Trees (Remember Your Algorithms Course?)
August 07, 2008 @ 12:03:23

On his Tower of Power blog Daniel Cousineau has written up a look at using a more detailed categorization method than just a parent/child relationship on your data - Tree Traversals.

If the software calls for only 2 levels of categorization (Parent and Child only), a simple nested for loop will suffice. However, software requirements change and you'll soon find yourself up shit creek without a paddle if you need to support 3 or 4 levels of nesting. [...] To those who's training is less formal (most web developers I meet have practical training, not formal), I'll help you out: Tree Traversals (or if you are completely lost, Recursion).

He creates a recursive function that, when passed in a category set with different types in it, can handle each of them and then calls itself again with the new child data. His sample code creates url out of a set of categories.

0 comments voice your opinion now!
tree category recursion tutorial parent child loop treetraversal


blog comments powered by Disqus

Similar Posts

HowTo Forge: How To Harden PHP5 With Suhosin On Fedora 7

Andreas Gohr's Blog: A Pirate Map with LibGD and Google Maps

Tony Lukasavage's Blog: PHP Debugging on IntelliJ IDEA 10 with Xdebug

Daniel Cousineau's Blog: Displaying N-Deep Trees (Remember Your Algorithms Course?)

NetTuts.com: Refactoring Legacy Code - Part 10: Dissecting Long Methods with Extractions


Community Events





Don't see your event here?
Let us know!


list series language composer interview community tool release framework podcast library artisanfiles laravel voicesoftheelephpant opinion symfony conference security version introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework