3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = <<< XML <?xml version="1.0" encoding="utf-8"?> <books> <book>Patterns of Enterprise Application Architecture</book> <book></book> <book>Design Patterns: Elements of Reusable Software Design</book> <book>Clean Code</book> </books> XML; $dom = new DOMDocument; $dom->loadXML($xml); $books = $dom->getElementsByTagName('book'); $length = $books->length; $break = FALSE; foreach ($books as $k => $book) { var_dump($book); if($break){ if($k == ($length)) { echo "last iteration: " . $book->nodeValue; } else { continue; } } if(empty($book)) { $break = TRUE; continue; } echo $book->nodeValue, PHP_EOL; }
Output for 8.3.0 - 8.3.7
object(DOMElement)#4 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(47) "Patterns of Enterprise Application Architecture" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(47) "Patterns of Enterprise Application Architecture" } Patterns of Enterprise Application Architecture object(DOMElement)#5 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } object(DOMElement)#4 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(53) "Design Patterns: Elements of Reusable Software Design" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(53) "Design Patterns: Elements of Reusable Software Design" } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(10) "Clean Code" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(10) "Clean Code" } Clean Code
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
object(DOMElement)#4 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(47) "Patterns of Enterprise Application Architecture" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(47) "Patterns of Enterprise Application Architecture" } Patterns of Enterprise Application Architecture object(DOMElement)#5 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } object(DOMElement)#4 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(53) "Design Patterns: Elements of Reusable Software Design" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(53) "Design Patterns: Elements of Reusable Software Design" } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "book" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(10) "Clean Code" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(10) "Clean Code" } Clean Code
Output for 8.0.0 - 8.0.30
object(DOMElement)#4 (23) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(47) "Patterns of Enterprise Application Architecture" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(47) "Patterns of Enterprise Application Architecture" } Patterns of Enterprise Application Architecture object(DOMElement)#5 (23) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } object(DOMElement)#4 (23) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(53) "Design Patterns: Elements of Reusable Software Design" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(53) "Design Patterns: Elements of Reusable Software Design" } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (23) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(10) "Clean Code" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(10) "Clean Code" } Clean Code
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
object(DOMElement)#4 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(47) "Patterns of Enterprise Application Architecture" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(47) "Patterns of Enterprise Application Architecture" } Patterns of Enterprise Application Architecture object(DOMElement)#5 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } object(DOMElement)#4 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(53) "Design Patterns: Elements of Reusable Software Design" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(53) "Design Patterns: Elements of Reusable Software Design" } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(10) "Clean Code" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(10) "Clean Code" } Clean Code
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
object(DOMElement)#3 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(47) "Patterns of Enterprise Application Architecture" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(47) "Patterns of Enterprise Application Architecture" } Patterns of Enterprise Application Architecture object(DOMElement)#5 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } object(DOMElement)#3 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(53) "Design Patterns: Elements of Reusable Software Design" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(53) "Design Patterns: Elements of Reusable Software Design" } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (18) { ["tagName"]=> string(4) "book" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "book" ["nodeValue"]=> string(10) "Clean Code" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "book" ["baseURI"]=> string(1) "/" ["textContent"]=> string(10) "Clean Code" } Clean Code
Output for 5.4.0
object(DOMElement)#3 (0) { } Patterns of Enterprise Application Architecture object(DOMElement)#5 (0) { } object(DOMElement)#3 (0) { } Design Patterns: Elements of Reusable Software Design object(DOMElement)#5 (0) { } Clean Code

preferences:
187.42 ms | 402 KiB | 229 Q