国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php實(shí)現(xiàn)xml轉(zhuǎn)換數(shù)組的方法示例

2024-09-04 11:46:38
字體:
供稿:網(wǎng)友
  1. <?php 
  2. $info= '<?xml version="1.0"encoding="utf-8"?> 
  3.       <data> 
  4.         <GeocoderSearchResponse> 
  5.           <status>OK</status> 
  6.           <result> 
  7.             <location> 
  8.               <lat>39.94921</lat> 
  9.               <lng>116.463619</lng> 
  10.             </location> 
  11.           <precise>0</precise> 
  12.           <confidence>50</confidence> 
  13.           <level>腳本</level> 
  14.           </result> 
  15.         </GeocoderSearchResponse> 
  16.         <GeocoderSearchResponse> 
  17.           <status>OK</status> 
  18.           <result> 
  19.             <location> 
  20.               <lat>39</lat> 
  21.               <lng>116</lng> 
  22.             </location> 
  23.           <precise>0</precise> 
  24.           <confidence>50</confidence> 
  25.           <level>腳本123</level> 
  26.           </result> 
  27.         </GeocoderSearchResponse> 
  28.       </data>'; 
  29. $xml= simplexml_load_string($info); 
  30. functionxml2array($xmlobject) { 
  31.   if($xmlobject) { 
  32.     foreach((array)$xmlobjectas$k=>$v) { 
  33.       $data[$k] = !is_string($v) ? xml2array($v) :$v
  34.     } 
  35.     return$data
  36.   } 
  37. $data= xml2array($xml); 
  38. var_dump($data); 
  39. ?> 

運(yùn)行結(jié)果如下:

  1. array(1) { 
  2.  ["GeocoderSearchResponse"]=> 
  3.  array(2) { 
  4.   [0]=> 
  5.   array(2) { 
  6.    ["status"]=> 
  7.    string(2)"OK" 
  8.    ["result"]=> 
  9.    array(4) { 
  10.     ["location"]=> 
  11.     array(2) { 
  12.      ["lat"]=> 
  13.      string(8)"39.94921" 
  14.      ["lng"]=> 
  15.      string(10)"116.463619" 
  16.     } 
  17.     ["precise"]=> 
  18.     string(1)"0" 
  19.     ["confidence"]=> 
  20.     string(2)"50" 
  21.     ["level"]=> 
  22.     string(6)"腳本" 
  23.    } 
  24.   } 
  25.   [1]=> 
  26.   array(2) { 
  27.    ["status"]=> 
  28.    string(2)"OK" 
  29.    ["result"]=> 
  30.    array(4) { 
  31.     ["location"]=> 
  32.     array(2) { 
  33.      ["lat"]=> 
  34.      string(2)"39" 
  35.      ["lng"]=> 
  36.      string(3)"116" 
  37.     } 
  38.     ["precise"]=> 
  39.     string(1)"0" 
  40.     ["confidence"]=> 
  41.     string(2)"50" 
  42.     ["level"]=> 
  43.     string(9)"腳本123" 
  44.    } 
  45.   } 
  46.  } 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吴忠市| 景宁| 巴中市| 南华县| 梅州市| 河西区| 贞丰县| 中江县| 常州市| 岑巩县| 香格里拉县| 高州市| 淳安县| 青川县| 平潭县| 鹤壁市| 黑龙江省| 中方县| 邵东县| 抚顺市| 开远市| 疏附县| 德惠市| 静宁县| 陇西县| 黎川县| 丹江口市| 长子县| 奉贤区| 沈阳市| 玛多县| 嵊州市| 梨树县| 郎溪县| 宝鸡市| 汉阴县| 纳雍县| 昆山市| 淮南市| 正宁县| 航空|