Skip to content

Instantly share code, notes, and snippets.

@gr0g
Forked from jasondmoss/simpleXmlToArray.php
Created May 13, 2019 05:31
Show Gist options
  • Save gr0g/ba214dc8db51aa9c8e17a6856b510e7a to your computer and use it in GitHub Desktop.
Save gr0g/ba214dc8db51aa9c8e17a6856b510e7a to your computer and use it in GitHub Desktop.
Convert a SimpleXML object to associative array
<?php
/**
* Convert a SimpleXML object to an associative array
*
* @param object $xmlObject
*
* @return array
* @access public
*/
function simpleXmlToArray($xmlObject)
{
$array = [];
foreach ($xmlObject->children() as $node) {
$array[$node->getName()] = is_array($node) ? simplexml_to_array($node) : (string) $node;
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment