In php, the Array2xml class converts arrays into XML instances.

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.