Skip to content

Instantly share code, notes, and snippets.

@cergey-obr
Last active April 26, 2021 09:48
Show Gist options
  • Save cergey-obr/16384c40b7abad98f356 to your computer and use it in GitHub Desktop.
Save cergey-obr/16384c40b7abad98f356 to your computer and use it in GitHub Desktop.
Преобразование SimpleXMLElement в массив
/**
* Преобразует SimpleXMLElement в array
* @param SimpleXMLElement $xml
* @return array
*/
private static function xmlToArray($xml) {
$xml = (array) $xml;
if(empty($xml)) {
return null;
}
foreach ($xml as $key=>$val) {
if ($val instanceof SimpleXMLElement) {
$xml[$key] = self::xmlToArray($val);
} elseif (empty($val)) {
$xml[$key] = null;
}
}
return $xml;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment