<?phpnamespace Home\controller; UseThink\controller;classIndexcontrollerextendsController { Public functionindex () {$arr[' one '] = ' Hello '; $arr[' both '] = ' Hi '; $arr[' three '] = ' Hello '; $arr[' four '] = ' Ahan '; Dump ($arr); //arrays into XML strings $curl _xml= Xml_encode ($arr, ' param '); Dump ($curl _xml); //XML strings into XML objects $xml=simplexml_load_string($curl _xml); Dump ($xml); //XML object loaded into an XML string $str=$xml-Asxml (); Dump ($str); //XML string Conversion array $attr= Json_decode (Json_encode ($xml),TRUE); Dump ($attr); }}
Simplexml_load_string (): Gets the SimpleXMLElement object from the XML string (the function loads the XML string into the object) if it fails, it returns Falsesimplexml_load_file (string, Class,options,ns,is_prefix); string is required to specify the XML string to use, class is optional, the class of the new object is specified, the two methods are the same as getting the string, and the other is getting the file if (file_ Exists ('.. /common/timesmap.xml ') {$xml = '). /common/timesmap.xml '; $str = file_get_contents ($xml);//convert XML file to XML string}
XML strings, XML objects, inter-array conversions