/** * Finds a particular TreeNode * * @param int $id the id to find * @param array $list the list of elements to search * @return Treenode upon success; null on failure */ public static function find($id, array &$list) { foreach ($list as $item) { if ($item->id == $id) { return $item; } if ($item->hasChildren()) { if ($current = TreeNode::find($id, $item->children)) { return $current; } } } return null; }