title: DomDocument removeChild in foreach reindexing the dom
body: <p>I am trying to delete <code>p</code> tags with <code>data-spotid</code> attribute</p>
  
  <pre><code>        $dom = new DOMDocument();
          @$dom-&gt;loadHTML($description);
          $pTag = $dom-&gt;getElementsByTagName('p');
  
          foreach ($pTag as $value) {
              /** @var DOMElement $value */
              $id = $value-&gt;getAttribute('data-spotid');
              if ($id) {
                  $value-&gt;parentNode-&gt;removeChild($value);
              }
          }
  </code></pre>
  
  <p>but when i am removing child it is reindexing the dom. let suppose i have 8 items i deleted 1st it will reindex it and 2nd element will become 1st and it will not delete it will go to 2nd which is now 3rd element.</p>