rewind(); $xml->valid(); $xml->next()) { $key = $xml->key(); if(!isset($a[$key])) { $a[$key] = array(); $i=0; } else $i = count($a[$key]); $simple = true; foreach($xml->current()->attributes() as $k=>$v) { $a[$key][$i][$k]=(string)$v; $simple = false; } if($xml->hasChildren()) { if($simple) $a[$key][$i] = xmlToArray($xml->current()); else $a[$key][$i]['content'] = xmlToArray($xml->current()); } else { if($simple) $a[$key][$i] = strval($xml->current()); else $a[$key][$i]['content'] = strval($xml->current()); } $i++; } return $a; }