This article mainly introduces PHP's method of converting array into xml, involving php's array traversal and xml format file construction skills, which has some reference value, for more information about how to convert an array into xml in PHP, see the following example. We will share this with you for your reference. The details are as follows:
" . $array . "
\n"; }}else{ foreach ($array as $key => $value) { $haveTag = true; if (is_numeric($key)) { $key = $keys; $haveTag = false; } if($elementLevel == 0 ) { $startElement = "<$key>"; $endElement = "
"; } $text .= $startElement; if(!$haveTag) { $elementLevel++; $text .= "<$key>" . array_Xml($value, $key). "
\n"; }else{ $elementLevel++; $text .= array_Xml($value, $key); } $text .= $endElement; }}return $text;}$array = array("employees" => array("employee" => array(array("name" => "name one","position" => "position one"),array("name" => "name two","position" => "position two"),array("name" => "name three","position" => "position three"))));echo array_Xml($array);?>
I hope this article will help you with PHP programming.
For more articles about how to convert an array into xml in PHP, refer to the PHP Chinese website!