Php array to xml and xml conversion array instances. This article introduces two simple examples: converting php arrays to xml and xml arrays. I hope this article will help you. Php array to xml code: Copy the code below. This article will introduce two simple examples. php array to xml and xml to convert arrays. I hope this article will help you.
Php array to xml
The code is as follows: |
|
Function array2xml ($ array, $ xml = false ){ If ($ xml = false ){ $ Xml = new SimpleXMLElement (' '); } Foreach ($ array as $ key => $ value ){ If (is_array ($ value )){ Array2xml ($ value, $ xml-> addChild ($ key )); } Else { $ Xml-> addChild ($ key, $ value ); } } Return $ xml-> asXML (); } Header ('content-type: text/XML '); Print array2xml ($ array ); |
Php xml to array
The code is as follows: |
|
$ S = < Basic 1 4 3 1 2 EOS; $ A = json_decode (json_encode (array) simplexml_load_string ($ s), 1 ); Print_r ($ ); |
Convert the arrays into xml and xml conversion arrays. I hope this article will help you. Php array to xml code is as follows...