Skip to content

Instantly share code, notes, and snippets.

@damiankloip
Created April 25, 2012 16:03
Show Gist options
  • Save damiankloip/2490938 to your computer and use it in GitHub Desktop.
Save damiankloip/2490938 to your computer and use it in GitHub Desktop.
function xml_to_array(SimpleXMLIterator $xml) {
$out = array();
foreach ($xml as $key => $value) {
if ($xml->hasChildren()) {
$out[$key] = xml_to_array($value);
}
else {
if ($attributes = (array) $value->attributes()) {
$out['#attributes'] = $attributes['@attributes'];
}
$out[$key] = (string) $value;
}
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment