title: Displaying JSON Weather API Response in PHP
body: <p>After looking through so many other questions here I'm still stuck with this. First I've never used JSON data ever before and am finding what should be rather simple to be rather tricky.</p>
  
  <p>I have a JSON response like this from the DarkSky Weather API</p>
  
  <pre><code>{
      "latitude": -26.202271,
      "longitude": 28.043631,
      "timezone": "Africa\/Johannesburg",
      "daily": {
          "summary": "Light rain throughout the week, with high temperatures peaking at 28\u00b0C on Saturday.",
          "icon": "rain",
          "data": [
              {
                  "time": 1549317600,
                  "summary": "Mostly cloudy throughout the day.",
                  "icon": "partly-cloudy-day",
                  "sunriseTime": 1549338410,
                  "sunsetTime": 1549385960,
                  "moonPhase": 0.02,
                  "precipIntensity": 0.0737,
                  "precipIntensityMax": 0.6121,
                  "precipIntensityMaxTime": 1549368000,
                  "precipProbability": 0.14,
                  "precipType": "rain",
                  "temperatureHigh": 22.68,
                  "temperatureHighTime": 1549364400,
                  "temperatureLow": 15.14,
                  "temperatureLowTime": 1549422000,
                  "apparentTemperatureHigh": 22.68,
                  "apparentTemperatureHighTime": 1549364400,
                  "apparentTemperatureLow": 15.14,
                  "apparentTemperatureLowTime": 1549422000,
                  "dewPoint": 13.85,
                  "humidity": 0.74,
                  "pressure": 1015.08,
                  "windSpeed": 1.84,
                  "windGust": 7.01,
                  "windGustTime": 1549342800,
                  "windBearing": 40,
                  "cloudCover": 0.73,
                  "uvIndex": 8,
                  "uvIndexTime": 1549357200,
                  "visibility": 14.03,
                  "ozone": 263.92,
                  "temperatureMin": 15.02,
                  "temperatureMinTime": 1549339200,
                  "temperatureMax": 22.68,
                  "temperatureMaxTime": 1549364400,
                  "apparentTemperatureMin": 15.02,
                  "apparentTemperatureMinTime": 1549339200,
                  "apparentTemperatureMax": 22.68,
                  "apparentTemperatureMaxTime": 1549364400
              },
              {
                  "time": 1549404000,
                  "summary": "Mostly cloudy throughout the day.",
                  "icon": "partly-cloudy-day",
                  "sunriseTime": 1549424856,
                  "sunsetTime": 1549472325,
                  "moonPhase": 0.05,
                  "precipIntensity": 0.0432,
                  "precipIntensityMax": 0.2819,
                  "precipIntensityMaxTime": 1549454400,
                  "precipProbability": 0.13,
                  "precipType": "rain",
                  "temperatureHigh": 24.32,
                  "temperatureHighTime": 1549454400,
                  "temperatureLow": 15.83,
                  "temperatureLowTime": 1549508400,
                  "apparentTemperatureHigh": 24.32,
                  "apparentTemperatureHighTime": 1549454400,
                  "apparentTemperatureLow": 15.83,
                  "apparentTemperatureLowTime": 1549508400,
                  "dewPoint": 13.06,
                  "humidity": 0.67,
                  "pressure": 1013.86,
                  "windSpeed": 1.34,
                  "windGust": 6.01,
                  "windGustTime": 1549414800,
                  "windBearing": 341,
                  "cloudCover": 0.71,
                  "uvIndex": 8,
                  "uvIndexTime": 1549443600,
                  "visibility": 16.09,
                  "ozone": 258.39,
                  "temperatureMin": 15.14,
                  "temperatureMinTime": 1549422000,
                  "temperatureMax": 24.32,
                  "temperatureMaxTime": 1549454400,
                  "apparentTemperatureMin": 15.14,
                  "apparentTemperatureMinTime": 1549422000,
                  "apparentTemperatureMax": 24.32,
                  "apparentTemperatureMaxTime": 1549454400
              },
              {
                  "time": 1549490400,
                  "summary": "Light rain overnight.",
                  "icon": "rain",
                  "sunriseTime": 1549511300,
                  "sunsetTime": 1549558690,
                  "moonPhase": 0.08,
                  "precipIntensity": 0.16,
                  "precipIntensityMax": 0.6096,
                  "precipIntensityMaxTime": 1549573200,
                  "precipProbability": 0.23,
                  "precipType": "rain",
                  "temperatureHigh": 25.43,
                  "temperatureHighTime": 1549540800,
                  "temperatureLow": 16.47,
                  "temperatureLowTime": 1549591200,
                  "apparentTemperatureHigh": 25.43,
                  "apparentTemperatureHighTime": 1549540800,
                  "apparentTemperatureLow": 16.61,
                  "apparentTemperatureLowTime": 1549591200,
                  "dewPoint": 14.17,
                  "humidity": 0.69,
                  "pressure": 1013.06,
                  "windSpeed": 2.28,
                  "windGust": 7.57,
                  "windGustTime": 1549497600,
                  "windBearing": 342,
                  "cloudCover": 0.52,
                  "uvIndex": 12,
                  "uvIndexTime": 1549533600,
                  "visibility": 16.09,
                  "ozone": 251.95,
                  "temperatureMin": 15.83,
                  "temperatureMinTime": 1549508400,
                  "temperatureMax": 25.43,
                  "temperatureMaxTime": 1549540800,
                  "apparentTemperatureMin": 15.83,
                  "apparentTemperatureMinTime": 1549508400,
                  "apparentTemperatureMax": 25.43,
                  "apparentTemperatureMaxTime": 1549540800
              },
              {
                  "time": 1549576800,
                  "summary": "Mostly cloudy throughout the day.",
                  "icon": "partly-cloudy-day",
                  "sunriseTime": 1549597745,
                  "sunsetTime": 1549645053,
                  "moonPhase": 0.11,
                  "precipIntensity": 0.2819,
                  "precipIntensityMax": 1.1481,
                  "precipIntensityMaxTime": 1549584000,
                  "precipProbability": 0.39,
                  "precipType": "rain",
                  "temperatureHigh": 25.17,
                  "temperatureHighTime": 1549627200,
                  "temperatureLow": 16.64,
                  "temperatureLowTime": 1549677600,
                  "apparentTemperatureHigh": 25.19,
                  "apparentTemperatureHighTime": 1549627200,
                  "apparentTemperatureLow": 16.64,
                  "apparentTemperatureLowTime": 1549677600,
                  "dewPoint": 15.46,
                  "humidity": 0.77,
                  "pressure": 1013.3,
                  "windSpeed": 1.21,
                  "windGust": 5.91,
                  "windGustTime": 1549580400,
                  "windBearing": 310,
                  "cloudCover": 0.91,
                  "uvIndex": 7,
                  "uvIndexTime": 1549616400,
                  "visibility": 16.09,
                  "ozone": 249.44,
                  "temperatureMin": 16.47,
                  "temperatureMinTime": 1549591200,
                  "temperatureMax": 25.17,
                  "temperatureMaxTime": 1549627200,
                  "apparentTemperatureMin": 16.61,
                  "apparentTemperatureMinTime": 1549591200,
                  "apparentTemperatureMax": 25.19,
                  "apparentTemperatureMaxTime": 1549627200
              },
              {
                  "time": 1549663200,
                  "summary": "Rain overnight.",
                  "icon": "rain",
                  "sunriseTime": 1549684188,
                  "sunsetTime": 1549731414,
                  "moonPhase": 0.14,
                  "precipIntensity": 0.221,
                  "precipIntensityMax": 0.7645,
                  "precipIntensityMaxTime": 1549670400,
                  "precipProbability": 0.27,
                  "precipType": "rain",
                  "temperatureHigh": 27.92,
                  "temperatureHighTime": 1549713600,
                  "temperatureLow": 16.84,
                  "temperatureLowTime": 1549760400,
                  "apparentTemperatureHigh": 27.92,
                  "apparentTemperatureHighTime": 1549713600,
                  "apparentTemperatureLow": 16.93,
                  "apparentTemperatureLowTime": 1549760400,
                  "dewPoint": 14.08,
                  "humidity": 0.67,
                  "pressure": 1011.76,
                  "windSpeed": 0.19,
                  "windGust": 6.53,
                  "windGustTime": 1549688400,
                  "windBearing": 145,
                  "cloudCover": 0.94,
                  "uvIndex": 7,
                  "uvIndexTime": 1549702800,
                  "visibility": 16.09,
                  "ozone": 253.47,
                  "temperatureMin": 16.64,
                  "temperatureMinTime": 1549677600,
                  "temperatureMax": 27.92,
                  "temperatureMaxTime": 1549713600,
                  "apparentTemperatureMin": 16.64,
                  "apparentTemperatureMinTime": 1549677600,
                  "apparentTemperatureMax": 27.92,
                  "apparentTemperatureMaxTime": 1549713600
              },
              {
                  "time": 1549749600,
                  "summary": "Rain in the morning.",
                  "icon": "rain",
                  "sunriseTime": 1549770632,
                  "sunsetTime": 1549817775,
                  "moonPhase": 0.17,
                  "precipIntensity": 1.0668,
                  "precipIntensityMax": 4.2316,
                  "precipIntensityMaxTime": 1549760400,
                  "precipProbability": 0.43,
                  "precipType": "rain",
                  "temperatureHigh": 24.07,
                  "temperatureHighTime": 1549803600,
                  "temperatureLow": 17.25,
                  "temperatureLowTime": 1549854000,
                  "apparentTemperatureHigh": 24.07,
                  "apparentTemperatureHighTime": 1549803600,
                  "apparentTemperatureLow": 17.25,
                  "apparentTemperatureLowTime": 1549854000,
                  "dewPoint": 14.73,
                  "humidity": 0.72,
                  "pressure": 1011.87,
                  "windSpeed": 2.52,
                  "windGust": 7.58,
                  "windGustTime": 1549778400,
                  "windBearing": 358,
                  "cloudCover": 0.72,
                  "uvIndex": 14,
                  "uvIndexTime": 1549792800,
                  "visibility": 15.58,
                  "ozone": 257.27,
                  "temperatureMin": 16.84,
                  "temperatureMinTime": 1549760400,
                  "temperatureMax": 24.07,
                  "temperatureMaxTime": 1549803600,
                  "apparentTemperatureMin": 16.93,
                  "apparentTemperatureMinTime": 1549760400,
                  "apparentTemperatureMax": 24.07,
                  "apparentTemperatureMaxTime": 1549803600
              },
              {
                  "time": 1549836000,
                  "summary": "Mostly cloudy starting in the afternoon.",
                  "icon": "partly-cloudy-night",
                  "sunriseTime": 1549857075,
                  "sunsetTime": 1549904134,
                  "moonPhase": 0.2,
                  "precipIntensity": 0.0381,
                  "precipIntensityMax": 0.2489,
                  "precipIntensityMaxTime": 1549886400,
                  "precipProbability": 0.13,
                  "precipType": "rain",
                  "temperatureHigh": 26.19,
                  "temperatureHighTime": 1549890000,
                  "temperatureLow": 15.78,
                  "temperatureLowTime": 1549944000,
                  "apparentTemperatureHigh": 26.19,
                  "apparentTemperatureHighTime": 1549890000,
                  "apparentTemperatureLow": 15.78,
                  "apparentTemperatureLowTime": 1549944000,
                  "dewPoint": 12.99,
                  "humidity": 0.61,
                  "pressure": 1008.71,
                  "windSpeed": 2.54,
                  "windGust": 8.12,
                  "windGustTime": 1549857600,
                  "windBearing": 326,
                  "cloudCover": 0.47,
                  "uvIndex": 15,
                  "uvIndexTime": 1549879200,
                  "visibility": 16.09,
                  "ozone": 246.75,
                  "temperatureMin": 17.25,
                  "temperatureMinTime": 1549854000,
                  "temperatureMax": 26.19,
                  "temperatureMaxTime": 1549890000,
                  "apparentTemperatureMin": 17.25,
                  "apparentTemperatureMinTime": 1549854000,
                  "apparentTemperatureMax": 26.19,
                  "apparentTemperatureMaxTime": 1549890000
              },
              {
                  "time": 1549922400,
                  "summary": "Rain in the afternoon.",
                  "icon": "rain",
                  "sunriseTime": 1549943518,
                  "sunsetTime": 1549990493,
                  "moonPhase": 0.24,
                  "precipIntensity": 0.3912,
                  "precipIntensityMax": 1.6332,
                  "precipIntensityMaxTime": 1549972800,
                  "precipProbability": 0.48,
                  "precipType": "rain",
                  "temperatureHigh": 22.24,
                  "temperatureHighTime": 1549983600,
                  "temperatureLow": 16.23,
                  "temperatureLowTime": 1550030400,
                  "apparentTemperatureHigh": 22.24,
                  "apparentTemperatureHighTime": 1549983600,
                  "apparentTemperatureLow": 16.23,
                  "apparentTemperatureLowTime": 1550030400,
                  "dewPoint": 13.89,
                  "humidity": 0.72,
                  "pressure": 1008.8,
                  "windSpeed": 1.88,
                  "windGust": 8.13,
                  "windGustTime": 1549972800,
                  "windBearing": 1,
                  "cloudCover": 0.94,
                  "uvIndex": 6,
                  "uvIndexTime": 1549958400,
                  "visibility": 16.09,
                  "ozone": 244.47,
                  "temperatureMin": 15.78,
                  "temperatureMinTime": 1549944000,
                  "temperatureMax": 22.24,
                  "temperatureMaxTime": 1549983600,
                  "apparentTemperatureMin": 15.78,
                  "apparentTemperatureMinTime": 1549944000,
                  "apparentTemperatureMax": 22.24,
                  "apparentTemperatureMaxTime": 1549983600
              }
          ]
      },
      "offset": 2
  }
  </code></pre>
  
  <p>What I am trying to achieve now is to extract the temperatureHigh and temperatureLow for the next 5 days excluding today or yesterday. </p>
  
  <p>Based on the above code being fresh from today 2019-02-05 the first two days need to be excluded. So I want to start the forecast data I extract from the timestamp <code>1549490400</code></p>
  
  <p>What I would like to end up with is the following display of echoed data.</p>
  
  <pre><code>Johannesburg
  Wednesday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Thursday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Friday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Saturday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Sunday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Monday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  </code></pre>
  
  <p>I would also like to perhaps do only a 3-day forecast like this</p>
  
  <pre><code>Johannesburg
  Wednesday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Thursday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  Friday [weathericon] MAX: `temperatureHigh` °C LOW: `temperatureLow` °C
  </code></pre>
  
  <p>Where I say [weathericon] I need to pull the <code>"icon": "rain"</code> for example from each day and match it with a locally stored .jpg / .png with the same name. ie. rain.png or rain.jpg</p>
  
  <p>I have tried various loops, foreach examples on other answers here but nothing seems to get me to display the data properly.</p>
  
  <p>Here's something I got partially working but due to my lack of understanding of JSON not sure why I am getting all the blank rows.</p>
  
  <pre><code>&lt;?php
  header('Content-Type: application/json');
  $json_string = file_get_contents("https://api.darksky.net/forecast/MYAPIKEY/-26.202271,28.043631?exclude=[currently,minutely,hourly,alerts,flags]&amp;units=si");
  $jsondata = json_decode($json_string, true);
  //Echo Data
  foreach ($jsondata as $max) {
    echo "MAX: ".$max['data'][2]['temperatureHigh']."\n";
    echo "MAX: ".$max['data'][3]['temperatureHigh']."\n";
    echo "MAX: ".$max['data'][4]['temperatureHigh']."\n";
  }
  ?&gt;
  </code></pre>
  
  <p>The above gives me this output</p>
  
  <pre><code>MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 
  MAX: 25.43
  MAX: 25.17
  MAX: 27.92
  MAX: 
  MAX: 
  MAX: 
  </code></pre>