3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<person> <child role="son1"> <child role="daughter1"/> </child> <child role="daughter2"> <child role="son2"> <child role="son3"/> </child> </child> </person>'; function xml2assoc($obj, &$arr) { $children = $obj->children(); foreach ( $children as $elementName => $node ) { if (!isset($arr[$elementName])) { $arr[$elementName] = array(); } $temp = array(); $attributes = $node->attributes(); foreach ( $attributes as $attributeName => $attributeValue ) { $attribName = strtolower(trim((string) $attributeName)); $attribVal = trim((string) $attributeValue); $temp[$attribName] = $attribVal; } $text = (string) $node; $text = trim($text); if (strlen($text) > 0) { $temp ['text='] = $text; } $arr[$elementName][] = $temp; $nextIdx = count($arr[$elementName]); xml2assoc($node, $arr[$elementName][$nextIdx - 1]); } return; } $dom = new SimpleXMLElement($xml); $arr = array(); xml2assoc($dom, $arr); print_r($arr);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [child] => Array ( [0] => Array ( [role] => son1 [child] => Array ( [0] => Array ( [role] => daughter1 ) ) ) [1] => Array ( [role] => daughter2 [child] => Array ( [0] => Array ( [role] => son2 [child] => Array ( [0] => Array ( [role] => son3 ) ) ) ) ) ) )

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:
156.27 ms | 409 KiB | 5 Q