"); // function call to convert array to xml if (!is_array ($data)) $data = array ($data); $this->array_to_xml ($data, $xml); //saving generated xml file print $xml->asXML(); } // function defination to convert array to xml private function array_to_xml ($data, &$xml) { foreach($data as $key => $value) { if(is_array($value)) { $key = is_numeric($key) ? "item$key" : $key; $subnode = $xml->addChild("$key"); $this->array_to_xml($value, $subnode); } else { $key = is_numeric($key) ? "item$key" : $key; $xml->addChild("$key","$value"); } } } }