3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Get an array of human readable times for sun events * @param \DateTime $date A \DateTime Object set to the desired date * and the correct timezone for the place in question * @param float $lat The latitude of the place in question * @param float $lon The longitude of the place in question * * @return array An associative array of human readable times sorted in chronological order. */ function adjustedSunInfo(\DateTime $date,$lat,$lon) { $sinfo=date_sun_info ($date->getTimestamp() ,$lat,$lon ); foreach($sinfo as $key=>$val) { //You should check that the value isn't 1 or empty first $time = new \DateTime('@' . $val); $time->setTimezone($date->getTimeZone()); $sinfo[$key] = $time->format('Y m d H:i:s'); } asort($sinfo); return $sinfo; } $time = new \DateTime('2013-01-01', new \DateTimeZone('Pacific/Chatham')); var_dump(adjustedSunInfo($time, -44.5, -176.2));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(9) { ["astronomical_twilight_begin"]=> string(19) "2013 01 01 03:22:47" ["nautical_twilight_begin"]=> string(19) "2013 01 01 04:24:22" ["civil_twilight_begin"]=> string(19) "2013 01 01 05:12:25" ["sunrise"]=> string(19) "2013 01 01 05:47:08" ["transit"]=> string(19) "2013 01 01 13:33:13" ["sunset"]=> string(19) "2013 01 01 21:19:19" ["civil_twilight_end"]=> string(19) "2013 01 01 21:54:02" ["nautical_twilight_end"]=> string(19) "2013 01 01 22:42:05" ["astronomical_twilight_end"]=> string(19) "2013 01 01 23:43:40" }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
array(9) { ["astronomical_twilight_begin"]=> string(19) "2013 01 01 03:22:47" ["nautical_twilight_begin"]=> string(19) "2013 01 01 04:24:22" ["civil_twilight_begin"]=> string(19) "2013 01 01 05:12:25" ["sunrise"]=> string(19) "2013 01 01 05:48:49" ["transit"]=> string(19) "2013 01 01 13:33:13" ["sunset"]=> string(19) "2013 01 01 21:17:37" ["civil_twilight_end"]=> string(19) "2013 01 01 21:54:02" ["nautical_twilight_end"]=> string(19) "2013 01 01 22:42:05" ["astronomical_twilight_end"]=> string(19) "2013 01 01 23:43:40" }
Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33
array(9) { ["astronomical_twilight_begin"]=> string(19) "2013 01 01 03:23:27" ["nautical_twilight_begin"]=> string(19) "2013 01 01 04:24:52" ["civil_twilight_begin"]=> string(19) "2013 01 01 05:12:52" ["sunrise"]=> string(19) "2013 01 01 05:49:14" ["transit"]=> string(19) "2013 01 01 13:33:26" ["sunset"]=> string(19) "2013 01 01 21:17:38" ["civil_twilight_end"]=> string(19) "2013 01 01 21:54:01" ["nautical_twilight_end"]=> string(19) "2013 01 01 22:42:01" ["astronomical_twilight_end"]=> string(19) "2013 01 01 23:43:26" }

preferences:
161.51 ms | 403 KiB | 262 Q