/** * Convert an xml tree to an associative array, supporting also duplicate keys * * @input $data give always an empty array * @input &$tags declarative array generated from xml_parse_into_struct() * @returns $data associative array */ public static function parse_array($data, &$tags, $force_multiple = array()) { do { if (is_array($tags)) { $entry = array_shift($tags); } else { return array(); } if (isset($entry["tag"])) { $tag = $entry["tag"]; } if (isset($entry["type"])) { $type = $entry["type"]; } if (isset($entry["value"])) { $value = $entry["value"]; } else { $value = ''; } //just add value if ($type == 'complete') { $data[$tag] = $value; } //open new tag if ($type == 'open') { if (isset($data[$tag])) { //if array is associative, it means it's not a collection of nodes with the same name if (EXmlParser::is_assoc($data[$tag])) { $prev = $data[$tag]; $new = EXmlParser::parse_array(array(), $tags, $force_multiple); $data[$tag] = array(); $data[$tag][] = $prev; $data[$tag][] = $new; } else { //it's already a collection $new = EXmlParser::parse_array(array(), $tags, $force_multiple); $data[$tag][] = $new; } } else { if (is_array($force_multiple) and in_array($tag, $force_multiple)) { $data[$tag] = array(); $data[$tag][] = EXmlParser::parse_array($data[$tag], $tags, $force_multiple); } else { $data[$tag] = array(); $data[$tag] = EXmlParser::parse_array($data[$tag], $tags, $force_multiple); } } } //close tags if ($type == 'close') { return $data; } } while (count($tags) > 0); return $data; }