0

Here my code

$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);

its returning this ;

"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"}
              ],

How to get 2nd line of data with php ?

Having first line ; $weather = $data['weather'][0]['description'];

logobi
  • 63
  • 1
  • 10

1 Answers1

2

If you want the second line, simply grap it this way:

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

or if you goal is to list all the result, just use a foreach.

Hyder B.
  • 10,900
  • 5
  • 51
  • 60