欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

这样的xml怎么循环

程序员文章站 2022-05-04 23:37:37
...
这样的xml如何循环
SimpleXMLElement Object
(
[date] => Array
(
[0] => 周五(今天, 实时:25)
[1] => 周六
[2] => 周日
[3] => 周一
)

[dayPictureUrl] => Array
(
[0] => http://api.map.baidu.com/images/weather/day/qing.png
[1] => http://api.map.baidu.com/images/weather/day/qing.png
[2] => http://api.map.baidu.com/images/weather/day/qing.png
[3] => http://api.map.baidu.com/images/weather/day/duoyun.png
)

[nightPictureUrl] => Array
(
[0] => http://api.map.baidu.com/images/weather/night/qing.png
[1] => http://api.map.baidu.com/images/weather/night/qing.png
[2] => http://api.map.baidu.com/images/weather/night/duoyun.png
[3] => http://api.map.baidu.com/images/weather/night/duoyun.png
)

[weather] => Array
(
[0] => 晴
[1] => 晴
[2] => 晴转多云
[3] => 多云
)

[wind] => Array
(
[0] => 北风3-4级
[1] => 南风微风
[2] => 南风微风
[3] => 南风微风
)

[temperature] => Array
(
[0] => 24 ~ 9
[1] => 21 ~ 10
[2] => 23 ~ 12
[3] => 22 ~ 11
)

)

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频