0

ここに私のコード

$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 で 2 行目のデータを取得するには?

最初の行を持つ; $weather = $data['weather'][0]['description'];

4

1 に答える 1

2

2 行目が必要な場合は、次のようにつかみます。

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

または、すべての結果をリストすることが目標の場合は、foreachを使用してください。

于 2016-04-22T22:55:56.430 に答える