3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($array, \SimpleXMLElement $xml) { foreach ($array as $key => $value) { if (is_array($value)) { if (!is_numeric($key)) { $subNode = $xml->addChild($key); } else { $subNode = $xml->addChild('item' . $key); } arrayToXml($value, $subNode); } else { $xml->addChild($key, htmlspecialchars($value)); } } } $array = [ 'key' => 'value', 'arrKey' => [ 'subkey1' => 1, 'subkey2' => 2, ], 0 => 'numeric zero', 1 => 'another', 2 => [ 'adin', 'two', 'three' ], ]; $xml = new \SimpleXMLElement('<response/>'); arrayToXml($array, $xml); echo $xml->asXML(); echo PHP_EOL; $xml = new SimpleXMLElement('<response/>'); array_walk_recursive(array_flip($array), array ($xml, 'addChild')); print $xml->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
<?xml version="1.0"?> <response><key>value</key><arrKey><subkey1>1</subkey1><subkey2>2</subkey2></arrKey><0>numeric zero</0><1>another</1><item2><0>adin</0><1>two</1><2>three</2></item2></response> Warning: array_flip(): Can only flip string and integer values, entry skipped in /in/KZ0JI on line 41 Warning: array_flip(): Can only flip string and integer values, entry skipped in /in/KZ0JI on line 41 Notice: Only variables should be passed by reference in /in/KZ0JI on line 41 <?xml version="1.0"?> <response><key>value</key><0>numeric zero</0><1>another</1></response>

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