Created
May 26, 2022 10:19
-
-
Save Ivanitch/f092a725244cd60a11fa09aa17d8b8da to your computer and use it in GitHub Desktop.
Преобразование SimpleXMLElement в массив
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Преобразует 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