3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $xml1 = new SimpleXmlIterator($str, 0, false); $xml = (array) $xml1; var_dump($xml); echo $xml['note']['to']; echo $xml['note']['recursive']['val'][0];
Output for 8.3.0 - 8.3.6
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Warning: Undefined array key "note" in /in/B7lnC on line 20 Warning: Trying to access array offset on null in /in/B7lnC on line 20 Warning: Undefined array key "note" in /in/B7lnC on line 21 Warning: Trying to access array offset on null in /in/B7lnC on line 21 Warning: Trying to access array offset on null in /in/B7lnC on line 21 Warning: Trying to access array offset on null in /in/B7lnC on line 21
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Warning: Undefined array key "note" in /in/B7lnC on line 20 Warning: Trying to access array offset on value of type null in /in/B7lnC on line 20 Warning: Undefined array key "note" in /in/B7lnC on line 21 Warning: Trying to access array offset on value of type null in /in/B7lnC on line 21 Warning: Trying to access array offset on value of type null in /in/B7lnC on line 21 Warning: Trying to access array offset on value of type null in /in/B7lnC on line 21
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Notice: Undefined index: note in /in/B7lnC on line 20 Notice: Trying to access array offset on value of type null in /in/B7lnC on line 20 Notice: Undefined index: note in /in/B7lnC on line 21 Notice: Trying to access array offset on value of type null in /in/B7lnC on line 21 Notice: Trying to access array offset on value of type null in /in/B7lnC on line 21 Notice: Trying to access array offset on value of type null in /in/B7lnC on line 21
Output for 7.3.32 - 7.3.33, 7.4.26
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Notice: Undefined index: note in /in/B7lnC on line 20 Notice: Undefined index: note in /in/B7lnC on line 21
Output for 5.1.2 - 5.1.6, 5.2.0 - 5.2.17
array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#2 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Notice: Undefined index: note in /in/B7lnC on line 20 Notice: Undefined index: note in /in/B7lnC on line 21
Output for 5.0.5, 5.1.0 - 5.1.1
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/B7lnC:16 Stack trace: #0 /in/B7lnC(16): SimpleXMLElement->__construct('<?xml version="...', 0, false) #1 {main} thrown in /in/B7lnC on line 16
Process exited with code 255.
Output for 5.0.3 - 5.0.4
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/B7lnC:16 Stack trace: #0 /in/B7lnC(16): SimpleXMLIterator->__construct('<?xml version="...', 0, false) #1 {main} thrown in /in/B7lnC on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/B7lnC:16 Stack trace: #0 {main} thrown in /in/B7lnC on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmliterator in /in/B7lnC on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmliterator in /in/B7lnC on line 16

preferences:
292.04 ms | 401 KiB | 400 Q