【问题标题】:how to get 2nd line of js data in php var OpenWeatherMap [duplicate]如何在php var OpenWeatherMap中获取第二行js数据[重复]
【发布时间】:2016-08-16 17:09:43
【问题描述】:

这是我的代码

$city="Delhi";
$country="IN"; 
$url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&units=metric&dt=1461412800&cnt=5&lang=en&APPID=xxxxx";
$json=file_get_contents($url);
$data=json_decode($json,true);

它返回这个;

"weather":[
                 {"id":520,"main":"Rain","description":"light intensity shower rain","icon":"09d"},
                 {"id":500,"main":"Rain","description":"light rain","icon":"10d"},
                 {"id":701,"main":"Mist","description":"mist","icon":"50d"}
              ],

如何用 php 获取第二行数据?

有第一行; $weather = $data['weather'][0]['description'];

【问题讨论】:

  • $data["weather"][1]["description"] 似乎是下一个合乎逻辑的步骤......

标签: javascript php openweathermap


【解决方案1】:

如果你想要第二行,只需这样抓住它:

$weather = $data['weather'][1]['description'];

或者如果您的目标是列出所有结果,只需使用foreach

【讨论】:

    猜你喜欢
    • 2015-10-06
    • 2013-02-13
    • 2014-04-04
    • 2020-04-07
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多