Skip to content

Instantly share code, notes, and snippets.

@drupalista-br
Created February 26, 2014 14:17
Show Gist options
  • Save drupalista-br/9230202 to your computer and use it in GitHub Desktop.
Save drupalista-br/9230202 to your computer and use it in GitHub Desktop.
<?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