jeremyfarrell Posted March 7, 2012 Share Posted March 7, 2012 i am brand new to php and thought a project looking at the weather undergound api would be a great place to "cut my teeth" and i am following up on a recent post i saw here http://www.phpfreaks.com/forums/index.php?topic=354658.msg1675207#msg1675207 the responder excellently described how to use the foreach function however i am not sure this is right for my application the project i am trying to accomplish is defining the freeze thaw cycle for the next ten days which i can accomplish in excel but thought this is a good way to learn to code. so my question is how should i do this, i have tried and failed with trying to pick out individual highs and lows data and define them as above or below freezing but i can't figure out how to pick out the right number my code for this part of the project is $json_line = file_get_contents("http://api.wunderground.com/api/{key}/geolookup/forecast10day/q/$zipcode.json"); $parsed_line = json_decode($json_line); echo $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'date'}->{'weekday'}; $temp_h = $parsed_line->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'high'}->{'farenheit'}; $temp_l = $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'low'}->{'farenheit'}; echo "Forecast for ${day} is:\n"; echo "High Temp is ${temp_h}<br />"; echo "Low Temp is ${temp_l}\n"; another road i was looking at going down was trying to do an array shift any help would be greatly appreciated thanks jeremy Link to comment https://forums.phpfreaks.com/topic/258427-beginner-help-with-php-json-array/ Share on other sites More sharing options...
trq Posted March 7, 2012 Share Posted March 7, 2012 What's with all the curly braces and quotes? $parsed_line->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'high'}->{'farenheit'}; should be.... $parsed_line->forecast->simpleforecast->forecastday->high->farenheit; Link to comment https://forums.phpfreaks.com/topic/258427-beginner-help-with-php-json-array/#findComment-1324715 Share on other sites More sharing options...
jeremyfarrell Posted March 7, 2012 Author Share Posted March 7, 2012 thank you i was emulating code from somewhere else- this is my first project so i must have already picked up a bad habit thanks again Link to comment https://forums.phpfreaks.com/topic/258427-beginner-help-with-php-json-array/#findComment-1324722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.