Created
February 26, 2014 14:17
-
-
Save drupalista-br/9230202 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
<?php | |
/** | |
* Converts an structured PHP array to XML. | |
* | |
* @param Array $data_array | |
* The array data for converting into XML. | |
* @param Object $xml_object | |
* The SimpleXMLElement Object | |
* | |
* @see https://gist.github.com/drupalista-br/9230016 | |
* | |
*/ | |
function array_to_xml($data_array, &$xml_object) { | |
foreach($data_array as $node) { | |
$subnode = $xml_object->addChild($node['#xml_tag'], $node['#xml_value']); | |
if ($node['#tag_attributes']) { | |
foreach ($node['#tag_attributes'] as $tag_attributes) { | |
$subnode->addAttribute($tag_attributes['name'], $tag_attributes['value']); | |
} | |
} | |
if ($node['#subnode']) { | |
array_to_xml($node['#subnode'], $subnode); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment