Last active
April 26, 2021 09:48
-
-
Save cergey-obr/16384c40b7abad98f356 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