首頁  >  文章  >  後端開發  >  这样的xml怎么循环

这样的xml怎么循环

WBOY
WBOY原創
2016-06-13 11:53:54808瀏覽

这样的xml如何循环

SimpleXMLElement Object<br />(<br />    [date] => Array<br />        (<br />            [0] => 周五(今天, 实时:25)<br />            [1] => 周六<br />            [2] => 周日<br />            [3] => 周一<br />        )<br /><br />    [dayPictureUrl] => Array<br />        (<br />            [0] => http://api.map.baidu.com/images/weather/day/qing.png<br />            [1] => http://api.map.baidu.com/images/weather/day/qing.png<br />            [2] => http://api.map.baidu.com/images/weather/day/qing.png<br />            [3] => http://api.map.baidu.com/images/weather/day/duoyun.png<br />        )<br /><br />    [nightPictureUrl] => Array<br />        (<br />            [0] => http://api.map.baidu.com/images/weather/night/qing.png<br />            [1] => http://api.map.baidu.com/images/weather/night/qing.png<br />            [2] => http://api.map.baidu.com/images/weather/night/duoyun.png<br />            [3] => http://api.map.baidu.com/images/weather/night/duoyun.png<br />        )<br /><br />    [weather] => Array<br />        (<br />            [0] => 晴<br />            [1] => 晴<br />            [2] => 晴转多云<br />            [3] => 多云<br />        )<br /><br />    [wind] => Array<br />        (<br />            [0] => 北风3-4级<br />            [1] => 南风微风<br />            [2] => 南风微风<br />            [3] => 南风微风<br />        )<br /><br />    [temperature] => Array<br />        (<br />            [0] => 24 ~ 9<br />            [1] => 21 ~ 10<br />            [2] => 23 ~ 12<br />            [3] => 22 ~ 11<br />        )<br /><br />)<br />

如何循环这样的xml数据 放到数组里   array(array('date'=>'','dayPictureUrl'=>'','nightPictureUrl'=>'','weather'=>));
------解决方案--------------------
foreach($xml->date as $i=>$v) {<br />  $res[] = array(<br />    'date' => $v,<br />    'dayPictureUrl'=> $xml->dayPictureUrl[$i],<br />    'nightPictureUrl'=> $xml->nightPictureUrl[$i],<br />    'weather' => $xm->weather[$i],<br />  );<br />}<br />print_r($res);<br />

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn