PHPHtmlParser\Dom\AbstractNode::getAncestor PHP Method

getAncestor() public method

Attempts to get an ancestor node by the given id.
public getAncestor ( integer $id ) : null | AbstractNode
$id integer
return null | AbstractNode
    public function getAncestor($id)
    {
        if (!is_null($this->parent)) {
            if ($this->parent->id() == $id) {
                return $this->parent;
            }
            return $this->parent->getAncestor($id);
        }
        return null;
    }

Usage Example

コード例 #1
0
 /**
  * Attempts to get an ancestor node by the given id.
  *
  * @param int $id
  * @return null|AbstractNode
  */
 public function getAncestor($id)
 {
     if (!is_null($this->parent)) {
         if ($this->parent->id() == $id) {
             return $this->parent;
         }
         return $this->parent->getAncestor($id);
     }
     return null;
 }