Created
September 4, 2015 18:33
-
-
Save goreilly/6c3881184b64d9a71e88 to your computer and use it in GitHub Desktop.
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
/** | |
* Note: Also removes anything after the _ in the key. Useful for | |
* adding nodes with the same name. e.g. Node_1 and Node_2 both become Node. | |
* Appends child to argument by reference. | |
* @param array $element | |
* @param \SimpleXMLElement $parent | |
* @return \SimpleXMLElement | |
*/ | |
protected function arrayToXml (array $element, \SimpleXMLElement $parent) { | |
foreach ($element as $key => $child) { | |
// Removes text after first _ | |
$key = explode('_', $key)[0]; | |
if (is_array($child)) { | |
$this->arrayToXml($child, $parent->addChild($key)); | |
} else { | |
$parent->addChild($key, $child); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment