: This article mainly describes how to convert XML and arrays. For more information about PHP tutorials, see. Two methods: Recursive conversion of arrays and xml
$ V) {if ($ v instanceof simplexmlelement | is_array ($ v) {$ sim [$ k] = toarray ($ v) ;}} return $ sim ;} $ sx = simplexml_load_file ('. /try. XML'); print_r ($ sx); print_r (toarray ($ sx); // you can see the source code, error $ arr = array ('a' => '000000', 'B' => '000000 ', 'C' => array ('D' => 'hahahaha', 'E' => array ('who' => 'The X '))); // Convert the array to xml, and add the new array to the new xml. arr to xmlfunction toxml ($ arr, $ node = null) {// create a new xml file if ($ node = null) {$ simxml = new simpleXMLElement ('
');} Else {$ simxml = $ node;} // foreach ($ arr as $ k => $ v) {if (is_array ($ v )) {// addChild (node name, content) // if it is an array, you need to create a node and put the content in this array -- "v is an array, // The main node name is k. next time, put the things into this sim-> addchild toxml ($ v, $ simxml-> addChild ($ k )); // if the array key is a number, you need to give it a tag name, because using a number directly causes problems} else if (is_numeric ($ k )) {$ simxml-> addChild ('item', $ v );} else {// add the child element key name-key value $ simxml-> addChild ($ k, $ v) directly if it is not an array );}} return $ simxml-> saveXML ();} header ('content-type: text/XML'); e Cho toxml ($ arr);?>
The above section describes how to convert XML and arrays, including some content. I hope my friends who are interested in PHP tutorials can help me.