user3652383
user3652383

Reputation:

How to echo out a result from this var_dump()?

This seems like it should be easy but I'm clearly just misunderstanding something. I'm making an API call to 5 Day Weather with the following code:

$file = file_get_contents("http://5DayWeather.org/api.php?city=Glasgow");
$weather = json_decode($file);

If i var_dump($weather) I get the following output:

object(stdClass)#1824 (2) {
   ["apiVersion"]=> string(3) "1.0"
   ["data"]=> object(stdClass)#1826 (7) {
      ["location"]=> string(12) "Glasgow, GBR"
      ["temperature"]=> string(2) "55" 
      ["skytext"]=> string(13) "Partly Cloudy" 
      ["humidity"]=> string(2) "88" 
      ["wind"]=> string(1) "8" 
      ["date"]=> string(10) "2014-10-03" 
      ["day"]=> string(6) "Friday"
   }
}

Right, that's all well and good, but how can I echo out single results? I feel like I've tried everything and just can't get anything to work, including (many for good measure):

$weather->temperature;
$weather['temperature'];
$weather{'temperature'};

I appreciate that it's my fundamental misunderstanding of how this array/object thing works but I've tried looking into it and can't figure out exactly what I should be doing with this feed.

Thanks a lot!

Upvotes: 1

Views: 82

Answers (1)

Daan
Daan

Reputation: 12236

Try this:

echo $weather->data->temperature;

Upvotes: 2

Related Questions