pQuery\DomNode::index PHP Method

index() public method

Index of node in parent
public index ( boolean $count_all = true ) : integer
$count_all boolean True to count all tags, false to ignore text and comments
return integer -1 if not found
    function index($count_all = true)
    {
        if (!$this->parent) {
            return -1;
        } elseif ($count_all) {
            return $this->parent->findChild($this);
        } else {
            $index = -1;
            //foreach($this->parent->children as &$c) {
            //	if (!$c->isTextOrComment()) {
            //		++$index;
            //	}
            //	if ($c === $this) {
            //		return $index;
            //	}
            //}
            foreach (array_keys($this->parent->children) as $k) {
                if (!$this->parent->children[$k]->isTextOrComment()) {
                    ++$index;
                }
                if ($this->parent->children[$k] === $this) {
                    return $index;
                }
            }
            return -1;
        }
    }
DomNode