3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function solstice() { // Set timezone date_default_timezone_set('UTC'); $date='2014/01/01'; $end_date='2014/12/31'; $i = 0; //loop through the year while(strtotime($date)<=strtotime($end_date)) { $sunrise=date_sunrise(strtotime($date),SUNFUNCS_RET_DOUBLE,31.47,35.13,90,3); $sunset=date_sunset(strtotime($date),SUNFUNCS_RET_DOUBLE,31.47,35.13,90,3); //calculate time difference $delta = $sunset-$sunrise; //store the time difference $delta_array[$i] = $delta; //store the date $dates_array[$i] = $date; $i++; //next day $date=date("Y-m-d",strtotime("+1 day",strtotime($date))); } $shortest_key = array_search(min($delta_array), $delta_array); $longest_key = array_search(max($delta_array), $delta_array); echo "The longest day is:".$dates_array[$longest_key]. "<br />"; echo "The shortest day is:".$dates_array[$shortest_key]. "<br />"; } solstice();
Output for 5.1.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
The longest day is:2014-06-21<br />The shortest day is:2014-12-21<br />
Output for 5.1.0 - 5.1.1
The longest day is:2014-06-21<br />The shortest day is:2014-12-22<br />
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/QncE9 on line 5
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: date_default_timezone_set() in /in/QncE9 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: date_default_timezone_set() in /in/QncE9 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: date_default_timezone_set() in /in/QncE9 on line 5