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 foreach ($xml->item as $item) { if ($item->images->image->count() > 1) { // Clone entry $images = clone $item->images; // Remove entry and replace with empty unset($item->images); $item->addChild('images'); var_dump($images->image); foreach ($images->image as $key => $img ) { var_dump($key,$img); $name = 'image' . ($key) ?: ''; $item->images->addChild($name, $img); } } } //$xml->asXML('POTO.xml'); echo $xml->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
object(SimpleXMLElement)#6 (3) { [0]=> string(1) "A" [1]=> string(1) "B" [2]=> string(1) "C" } string(5) "image" object(SimpleXMLElement)#9 (1) { [0]=> string(1) "A" } string(5) "image" object(SimpleXMLElement)#10 (1) { [0]=> string(1) "B" } string(5) "image" object(SimpleXMLElement)#9 (1) { [0]=> string(1) "C" } <?xml version="1.0"?> <items> <item> <images><imageimage>A</imageimage><imageimage>B</imageimage><imageimage>C</imageimage></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:
42.82 ms | 402 KiB | 8 Q