3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); global $n; $n=0; function convert($xml) { $simpleXmlObj = simplexml_load_string($xml); $array = toarray($simpleXmlObj); return $array; } function toarray($simpleXmlObj) { $simpleXmlObjNew = array(); foreach (array_keys((array)$simpleXmlObj) as $element) { $el = (array)$simpleXmlObj->$element; if(isset($el[0])){ $trim = $el[0]; $simpleXmlObjNew[$element] = $trim; }else{ $simpleXmlObjNew[$element] = toarray($simpleXmlObj->$element); } if(empty( $simpleXmlObjNew[$element] )){ $simpleXmlObjNew[$element] = ''; } } return $simpleXmlObjNew; } $xml = <<<xml <?xml version="1.0" encoding="utf-8"?> <RESPONSE> <e></e> <e1> </e1> <e2> s </e2> <e3>s</e3> <e4> </e4> </RESPONSE> xml; $simpleXmlObj = simplexml_load_string($xml); $response = toarray($simpleXmlObj); print_r($response);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [e] => [e1] => SimpleXMLElement Object ( ) [e2] => s [e3] => s [e4] => SimpleXMLElement Object ( ) )

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