|
|
@@ -554,13 +554,13 @@ EOF';
|
|
|
|
|
|
public static function arrayToXML($array, $formatOutput = false, $root = "root") {
|
|
|
|
|
|
- function arrayToXML_rec($data, $dom, $node, $parent = null) {
|
|
|
+ $arrayToXML_rec = function($data, $dom, $node, $parent = null) use (&$arrayToXML_rec) {
|
|
|
$child = $dom->createElement($node);
|
|
|
if (!$parent) $parent = $dom;
|
|
|
if (is_array($data)) {
|
|
|
foreach ($data as $key => $value) {
|
|
|
- if (is_numeric($key)) arrayToXML_rec($value, $dom, $node, $parent);
|
|
|
- else arrayToXML_rec($value, $dom, $key, $child);
|
|
|
+ if (is_numeric($key)) $arrayToXML_rec($value, $dom, $node, $parent);
|
|
|
+ else $arrayToXML_rec($value, $dom, $key, $child);
|
|
|
}
|
|
|
} else {
|
|
|
if ($data) {
|
|
|
@@ -569,13 +569,13 @@ EOF';
|
|
|
} else $parent->appendChild($child);
|
|
|
}
|
|
|
if ($child->hasChildNodes()) $parent->appendChild($child);
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
if (!is_array($array)) throw new Exception("First argument need to be an array");
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
|
$dom->preserveWhiteSpace = false;
|
|
|
$dom->formatOutput = $formatOutput;
|
|
|
- arrayToXML_rec($array, $dom, $root);
|
|
|
+ $arrayToXML_rec($array, $dom, $root);
|
|
|
return $dom->saveXML();
|
|
|
}
|
|
|
|