title: PHP tree implementation: Accessing parent node
body: <p>I have an own Tree object implemented in PHP. Say we have a tree like:</p>
  
  <pre>
  Root  
  |_ Folder 1  
  |_ Folder 2  
     |_ Subfolder 1
  </pre>
  
  <p>I can access <code>Subfolder 1</code> like this:</p>
  
  <pre><code>$sf1 = $Tree->NavigateTo("Folder 2/Subfolder 1")</code></pre>
  
  <p>And <code>$sf1</code> will hold the <code>Subfolder 1</code> node. I want to implement a <code>GetParentNode()</code>  method, so that  </p>
  
  <pre><code>$parent = $sf1->GetParentNode()  // Equivalent to Folder 2</code></pre>
  
  <p>This is the Tree definition:</p>
  
  <pre><code>class JaxpTree
  {
      /**
       * @var     JaxpTree|JaxpTreeNode    Array of Tree nodes.
       * @access  public
       */
      public $Nodes;
  
      /**
       * @var     JaxpList    Array of Tree items.
       * @access  public
       */
      public $ItemList;
  }
  </code></pre>
  
  <p>It works by nesting Tree objects, so Subfolder 1 can be accessed also like:</p>
  
  <pre><code>$Tree->Nodes["Folder 2"]->Nodes["Subfolder 1"]</code></pre>
  
  <p>which will be a TreeNode object:</p>
  
  <pre><code>/**
   * Represents a Tree node.
   *
   * @package     Jaxp.Trees
   * @subpackage  TreeNode
   * @since       1.0
   */
  
  class JaxpTreeNode
  {
      /**
       * @var     int Node id.
       * @access  public
       */
      public $Id;
  
      /**
       * @var     JaxpTreeNodeAttributes  Contains the node's attributes.
       * @access  public
       */
      public $Attributes;
  }
  </code></pre>
  
  <p>How can I implement parent node accessing here?</p>
  
  <h1>Solved</h1>
  
  <p>Solution is to add a Parent property which contains a reference to the parent node.
  Thanks!</p>