title: Recursively call function to get last record in a chain
body: <p>In our database, we have records in a single table where the ID of one record is the parentID of another. For example:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>ParentID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>123</td>
  <td>null</td>
  </tr>
  <tr>
  <td>456</td>
  <td>123</td>
  </tr>
  <tr>
  <td>789</td>
  <td>456</td>
  </tr>
  <tr>
  <td>011</td>
  <td>789</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>There is an existing function named <code>getchild</code> that can be passed an ID to get a child. For example calling <code>getChild(456)</code> would return record with ID 789. If no child exists, <code>NULL</code> is returned. So for another example, calling <code>getChild(011)</code> would return null, since no record has this as a parentID. getChild returns the data as a PHP object.</p>
  <p>I'd like to create a separate function (named getLastChild) that takes the first ID in the chain and recursively calls getChild() until the last record is reached and return it. For example <code>getLastchild(123)</code> should return record with ID 011.</p>
  <p>This is what I've tried so far that is not working</p>
  <pre><code>public function getLastChild($id){
      $child = getChild($id);
      while(!is_null($child)){
          $lastChild = getChild($child-&gt;id);
      }
      return $lastChild;
  }
  </code></pre>
  <p>Any suggestions would be appreciated!</p>