3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = <<<XML <data> <prod id="1"> <layer id="layer_0" imgSRC="data/361_layer_0.png"/> <layer id="layer_1" imgSRC="data/362_layer_0.png"/> <layer id="layer_2" imgSRC="data/363_layer_0.png"/> </prod> <prod id="2"> <layer id="layer_0" imgSRC="data/361_layer_0.png"/> <layer id="layer_1" imgSRC="data/362_layer_0.png"/> <layer id="layer_2" imgSRC="data/363_layer_0.png"/> </prod> </data> XML; $xml = simplexml_load_string($x); // assuming XML in $x $node = $xml->xpath("//prod[@id='2']/layer[@id='layer_2']")[0]; $new = $node->addChild("layer",""); $new->addAttribute("id", "layer_3"); var_dump ($xml);
Output for git.master, git.master_jit, rfc.property-hooks
object(SimpleXMLElement)#1 (1) { ["prod"]=> array(2) { [0]=> object(SimpleXMLElement)#4 (2) { ["@attributes"]=> array(1) { ["id"]=> string(1) "1" } ["layer"]=> array(3) { [0]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_0" ["imgSRC"]=> string(20) "data/361_layer_0.png" } } [1]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_1" ["imgSRC"]=> string(20) "data/362_layer_0.png" } } [2]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_2" ["imgSRC"]=> string(20) "data/363_layer_0.png" } } } } [1]=> object(SimpleXMLElement)#5 (2) { ["@attributes"]=> array(1) { ["id"]=> string(1) "2" } ["layer"]=> array(3) { [0]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_0" ["imgSRC"]=> string(20) "data/361_layer_0.png" } } [1]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_1" ["imgSRC"]=> string(20) "data/362_layer_0.png" } } [2]=> object(SimpleXMLElement)#6 (2) { ["@attributes"]=> array(2) { ["id"]=> string(7) "layer_2" ["imgSRC"]=> string(20) "data/363_layer_0.png" } ["layer"]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(1) { ["id"]=> string(7) "layer_3" } } } } } } }

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:
35.07 ms | 409 KiB | 8 Q