Skip to content

Instantly share code, notes, and snippets.

@drdim
Last active December 25, 2015 01:29
Show Gist options
  • Save drdim/6895764 to your computer and use it in GitHub Desktop.
Save drdim/6895764 to your computer and use it in GitHub Desktop.
array2xml
<?php
/**
* Преобразование в xml строку
* @param array $array
* @param string $tag
* @return string
*/
function array2xml($array = array(), $tag = "nodef")
{
$Output = '';
if (is_array($array) || $array instanceof ArrayIterator) {
foreach ($array as $rNum => $arr) {
$Output .= '<' . $tag . '>';
if (isset($arr) && is_array($arr) == true) {
foreach ($arr as $key => $value) {
$key = strtolower($key);
if (is_array($value)) {
$Output .= array2xml($value, $key);
}
else if ($value !== '') {
$Output .= '<' . $key . '>' . htmlspecialchars($value) . '</' . $key . '>';
}
}
}
$Output .= '</' . $tag . '>';
}
}
return ($Output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment