Exemplo n.º 1
0
 /**
  * Index of node in parent
  * @param bool $count_all True to count all tags, false to ignore text and comments
  * @return int -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;
     }
 }
Exemplo n.º 2
0
 /**
  * Index of node in parent
  * @param bool $count_all True to count all tags, false to ignore text and comments
  * @return int -1 if not found
  */
 public 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 $children) {
             if (!$children->isTextOrComment()) {
                 ++$index;
             }
             if ($children === $this) {
                 return $index;
             }
         }
         return -1;
     }
 }