Hello. There is such a code

<?php $content = file_get_contents ('http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1'); $json = json_decode($content, true); echo '<pre>'; print_r($json); foreach( $json['weather'] as $arr) { $weather = $arr['main']; } foreach ($json['main'] as $varray) { $temp = $varray['temp']; } echo "<h1>Город: $json[name]</br>Погода: $weather<br>Температура: $temp</h1>"; 

It is impossible to output the value of $ temp, since it is a floating point number. How can you finally get it out? And in general, is it right to output data from an array like this?

+ I would like in the same document to display a picture depending on the weather, how to organize the output of a picture (say, locally located)?

  • $ json ['main'] is not an array of arrays, but a regular associative array, get so $ temp = $ json ['main'] ['temp']; without foreach - Jean-Claude
  • Thank you, there was a question with a picture) Something Google does not help much. - Sindr0me
  • Well, for example, by the variable "light intensity drizzle" - if this value displays a sun picture with one drop, there will be another value - output the corresponding picture. then on the bunch-bunch. - Jean-Claude
  • I'm talking about what team can vyesti. And so everything is correctly derived with the condition if $ weather == Drizzle. And the picture echo '<img src = "path">' did not know simply that this construction was working. - Sindr0me

0