3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlStr = <<<XML <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <root></root> XML; $xml = new \SimpleXMLElement($xmlStr); $xml = assocToXml(['one' => 1, 'two' => ['three' => 3, 'four' => '4']], $xml); var_dump($xml); function assocToXml(array $array, \SimpleXMLElement $xml) { foreach ($array as $key => $value) { if (!is_array($value)) { if (is_string($key)) { $xml->addChild($key, $value); } } else { $xml->addChild($key); // $xml->{$key} = $value; assocToXml($value, $xml->{$key}); } } return $xml; }
Output for git.master, git.master_jit, rfc.property-hooks
object(SimpleXMLElement)#1 (2) { ["one"]=> string(1) "1" ["two"]=> object(SimpleXMLElement)#2 (2) { ["three"]=> string(1) "3" ["four"]=> string(1) "4" } }

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:
53.87 ms | 401 KiB | 8 Q