Skip to content

Instantly share code, notes, and snippets.

@mikkohei13
Last active October 12, 2015 02:58
Show Gist options
  • Save mikkohei13/3961444 to your computer and use it in GitHub Desktop.
Save mikkohei13/3961444 to your computer and use it in GitHub Desktop.
XML to Array
// Source: http://www.php.net/manual/en/book.simplexml.php#108035
function toArray(SimpleXMLElement $xml) {
$array = (array)$xml;
foreach ( array_slice($array, 0) as $key => $value ) {
if ( $value instanceof SimpleXMLElement ) {
$array[$key] = empty($value) ? NULL : toArray($value);
}
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment