PHP has a variety of xml operation classes, and xmltoarray methods also have a variety of, of course, the common is recursive traversal. Today, I read the php manual and found that there are many novel usage in the comments, although some of them are not perfect. Here are a few examples. 2lineXML2Array $ xml ?? Simplexml_load_string ($ xmlstring); $ arr
PHP has a variety of xml operation classes, and xml to array methods also have a variety of, of course, the common is recursive traversal. Today, I read the php manual and found that there are many novel usage in the comments, although some of them are not perfect. Here are a few examples. // 2 line XML2Array $ xml? =? Simplexml_load_string ($ xmlstring); $ arr
PHP has a variety of xml operation classes, and xml to array methods also have a variety of, of course, the common is recursive traversal. Today, I read the php manual and found that there are many novel usage in the comments, although some of them are not perfect. Here are a few examples.
// 2 line XML2Array $ xml? =? Simplexml_load_string ($ xmlstring); $ array? =? Json_decode (json_encode ($ xml), TRUE); // is a complete function? ToArray ($ xml ){? ? ? ?? $ Array? =? Json_decode (json_encode ($ xml ),? TRUE );? ? ? ??? ? ? ? Foreach (? Array_slice ($ array ,? 0)? $ Key? =>? $ Value ?) {? ? ? ? ? ? If (empty ($ value ))? $ Array [$ key] =? NULL ;? ? ? ? ? ? Elseif (? Is_array ($ value ))? $ Array [$ key] =? ToArray ($ value );? ? ? ? }? ? ? ? Return? $ Array ;? ? }
// 2 line XML2Array use forced type conversion $ xml = simplexml_load_string ($ file); $ array = (array) $ xml;
Original article address: [PHP] converts xml into an array. Thank you for sharing it.