3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($data, \SimpleXmlElement $element, $parent = null) { echo 'data: '; var_dump($data) ; echo $element->asXml(); echo 'parent: '.$parent; foreach ($data as $key => $value) { if (is_array($value) || $value instanceof \Traversable) { if (!is_numeric($key)) { if (count($value) > 0 && isset($value[0])) { arrayToXml($value, $element, $key); } else { $subnode = $element->addChild($key); arrayToXml($value, $subnode, $key); } } else { $subnode = $element->addChild($parent); arrayToXml($value, $subnode, $parent); } } else { if (!is_numeric($key)) { if (substr($key, 0, 1) === '@') { $element->addAttribute(substr($key, 1), $value); } elseif ($key === 'value' and count($data) === 1) { $element->{0} = $value; } elseif (is_bool($value)) { $element->addChild($key, intval($value)); } else { $element->addChild($key, htmlspecialchars($value, ENT_QUOTES)); } } else { $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES)); } } } } $data = array('x' => array('value' => 'test')); $doc = new \SimpleXMLElement('<resource href="/"></resource>'); arrayToXml($data, $doc); echo $doc->asXml(); //$xml = new \SimpleXMLElement('<resource href="/"><x><0>test</0></x></resource>'); //echo $xml->x;
Output for git.master, git.master_jit, rfc.property-hooks
data: array(1) { ["x"]=> array(1) { ["value"]=> string(4) "test" } } <?xml version="1.0"?> <resource href="/"/> parent: data: array(1) { ["value"]=> string(4) "test" } <x/>parent: x<?xml version="1.0"?> <resource href="/"><x><0>test</0></x></resource>

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