Skip to content

Instantly share code, notes, and snippets.

@Ivanitch
Created May 26, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanitch/f092a725244cd60a11fa09aa17d8b8da to your computer and use it in GitHub Desktop.
Save Ivanitch/f092a725244cd60a11fa09aa17d8b8da 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