pQuery\DomNode::typeIndex PHP Method

typeIndex() public method

Index of all similar nodes in parent
public typeIndex ( ) : integer
return integer -1 if not found
    function typeIndex()
    {
        if (!$this->parent) {
            return -1;
        } else {
            $index = -1;
            //foreach($this->parent->children as &$c) {
            //	if (strcasecmp($this->tag, $c->tag) === 0) {
            //		++$index;
            //	}
            //	if ($c === $this) {
            //		return $index;
            //	}
            //}
            foreach (array_keys($this->parent->children) as $k) {
                if (strcasecmp($this->tag, $this->parent->children[$k]->tag) === 0) {
                    ++$index;
                }
                if ($this->parent->children[$k] === $this) {
                    return $index;
                }
            }
            return -1;
        }
    }
DomNode