2016-04-22 12 views
0

ここでのPHPのvar OpenWeatherMap私のコードでは、JSデータの2行目を取得するためにどのよう

$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'];

+1

$データ["weather"] [1] ["description"] '次の論理的なステップのようです... – miken32

答えて

2

2番目の行をしたい場合は、単にそれをこのようにGRAP:

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

かの目標はただforeachを使用し、すべての結果を一覧表示する場合。