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 git.master, git.master_jit, rfc.property-hooks
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

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.44 ms | 413 KiB | 8 Q