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'); foreach ($images->image as $key => $img ) { $name = 'image' . ($key) ?: ''; $xml->item[$i]->images->addChild($name, $img); } } } //$xml->asXML('POTO.xml'); echo $xml->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $i in /in/Je1Af on line 27 Warning: Attempt to read property "images" on null in /in/Je1Af on line 27 Fatal error: Uncaught Error: Call to a member function addChild() on null in /in/Je1Af:27 Stack trace: #0 {main} thrown in /in/Je1Af on line 27
Process exited with code 255.

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.61 ms | 401 KiB | 8 Q