如何在 php var OpenWeatherMap 中获取第二行 js 数据
how to get 2nd line of js data in php var OpenWeatherMap
这是我的代码
$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'][0]['description'];
如果你想要第二行,只需这样抓取即可:
$weather = $data['weather'][1]['description'];
或者如果您的目标是列出所有结果,只需使用 foreach.
这是我的代码
$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'][0]['description'];
如果你想要第二行,只需这样抓取即可:
$weather = $data['weather'][1]['description'];
或者如果您的目标是列出所有结果,只需使用 foreach.