This article describes how to convert arrays into XML in the Array2xml class of php. The example shows how to convert arrays into XML and Array2xml is a very practical array conversion technique, for more information about how to convert arrays into XML, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
Xml ='
'; $ This-> xml. = $ this-> _ array2xml ($ array);} function getXml () {return $ this-> xml;} function _ array2xml ($ array) {$ xml = ''; foreach ($ array as $ key => $ val) {if (is_numeric ($ key) {$ key = "item id = \" $ key \"";} else {// Remove the space. only the text before the space is used is key list ($ key,) = explode ('', $ key);} $ xml. = "<$ key>"; $ xml. = is_array ($ val )? $ This-> _ array2xml ($ val): $ val; // Remove the space. The text is key list ($ key,) = explode ('', $ key); $ xml. ="
";}Return $ xml ;}}
I hope this article will help you with PHP programming.
For more articles about how to convert arrays into XML instances using the Array2xml class in php, refer to the PHP Chinese website!