3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$xml = simplexml_load_file('data.xml'); $xml = simplexml_load_string('<items> <item> <images> <image>A</image> <image>B</image> <image>C</image> </images> </item> </items>'); var_dump($xml); // Loop over items in original xml for($i = 0; $i < count($xml->item); $i++) { //$images; if( (count($xml->item[$i]->images->image)) > 1) { $images = $xml->item[$i]->images; // Remove entry unset($xml->item[$i]->images); $xml->item[$i]->addChild('images'); for($y = 0; $y < $images->image->count(); $y++) { if($y == 0) { $xx = $xml->item[$i]->images->addChild('image', $images->image[$y]); }else { $xml->item[$i]->images->addChild('image' . $y, $images->image[$y]); } } var_dump($images); } } //$xml->asXML('POTO.xml'); echo $xml->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
object(SimpleXMLElement)#1 (1) { ["item"]=> object(SimpleXMLElement)#2 (1) { ["images"]=> object(SimpleXMLElement)#3 (1) { ["image"]=> array(3) { [0]=> string(1) "A" [1]=> string(1) "B" [2]=> string(1) "C" } } } } object(SimpleXMLElement)#3 (0) { } <?xml version="1.0"?> <items> <item> <images/></item> </items>

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:
44.61 ms | 402 KiB | 8 Q