function struct_to_array($item) { if (!is_string($item)) { $item = (array) $item; foreach ($item as $key => $val) { $item[$key] = struct_to_array($val); } } return $item; }
public static function xml_to_array($xmlpath) { $xml = file_get_contents($xmlpath, true); $xml = preg_replace('/<!--.*-->/', '', $xml); $array = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); foreach ($array as $key => $item) { $array[$key] = struct_to_array((array) $item); } return $array; }