The problem of converting xml into arrays is as follows: XMLcode & lt; root & gt; & lt; rows & gt; & lt; errMsgtext = & quot;/& gt; & lt; retValuetext = & quot; true & quot;/& gt; & xml conversion to an array
The existing xml is as follows:
XML code
....
The xml depth is unknown, but each node has the text attribute. Is there any way to convert it into the following array?
PHP code
Array( [rows] => Array ( [errMsg] => [retValue] => true ) [records] => Array ( [productno] =>000321 [billno] => [orderno] =>D004410439 [out_trade_no] => 100001 [plcprem] =>0.0 [orderprem] =>50.0 [commision] =>0.0 ) .....)
------ Solution --------------------
Look at this
Http://weblog.thomassmart.com/2008/09/php-function-xml2array/
------ Solution --------------------
PHP code
$ S = <XML
XML; $ obj = simplexml_load_string ($ s); $ r = array (); foreach ($ obj as $ name => $ nodes) {foreach ($ nodes as $ k =>v v) {$ t = (array) $ v-> attributes ()-> text; $ r [$ name] [$ k] = $ t [0] ;}} print_r ($ r );
------ Solution --------------------
Discussion
PHP code
$ S = <XML
......