I have the following code
$date = new DateTime($json->date);
$hour = $date->format( 'H' );
$range = range($hour, 23, 3); // get the range for the data to be provided;
foreach($json->hourly as $hourlyData){
if(in_array($hourlyData->hour, $range)){
print_r($hourlyData->hour);echo '<br />';
}
}
the code above looks at current time. If time is 4, then it will add an echo for every 3 hours as the range would be (4,23, 3). This all is good. However, this above is only for current day. But for next day, I want the range to be reset and instead of from 4, it will be from 1 till 23. So the range will reset to (1,23,3) and so on.
what you need to use is
DateIntervalnot range ….Try
Output
I hope this helps