Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Implementing An N-Level Nested Tree In PHP And PostgreSQL, Part 1

A Sample Nested Tree

This web site uses a nested tree to structure the documents and the relationships between the documents. We refer to each document as a node. At time of writing, part of the PhpRiot nested was structured as such:

Listing 1 A Sample Nested Tree (listing-1.txt)
General Resources
   Code Paste
   Books & Publications

Just by looking at this structure, we can determine the following information:

  • The section is called General Resources, and has the children Code Paste, Documentation, Books & Publications and Links.
  • Documentation has three siblings: Code Paste, Books & Publications and Links
  • PostgreSQL has parent Books & Publications, and is an ancestor of General Resources
  • Portals is a descendants of General Resources.

Obviously there is much more that can be determined, but this hopefully demonstrates the point.

Although we refer to each item as a node, beacuse it’s a tree structure you could also use the following terminology:

  • A nodes with no children is a leaf
  • A node with children is a branch

In This Article