d
Amit DhamuSoftware Engineer
 

Convert XML to Array

1 minute read 00000 views
function XML2Array(SimpleXMLElement $parent) {
    $array = [];

    foreach ($parent as $name => $element) {
        ($node = & $array[$name])
            && (1 === count($node) ? $node = [$node] : 1)
            && $node = & $node[];

        $node = $element->count() ? $this->XML2Array($element) : trim($element);
    }
    return $array;
}

Source