3v4l.org

run code in 300+ PHP versions simultaneously
<?php const TIME_ZONE_FORMAT_NAME = 'utc'; const KEY_VALUE = 'value'; const KEY_NAME = 'name'; const KEY_OFFSET = 'offset'; const KEY_FORMAT = 'format'; const KEY_DISPLAY = 'display'; function convertTimezoneToArray($timezone, $value) { $dateTime = new \DateTime(); $dateTime->setTimeZone(new \DateTimeZone($timezone)); return [ self::KEY_VALUE => $value, self::KEY_NAME => $timezone, self::KEY_OFFSET => $dateTime->format('P'), self::KEY_FORMAT => self::TIME_ZONE_FORMAT_NAME ]; } function convertTimezoneList(array $timezonesForCountry) { $timezoneArray = []; foreach ($timezonesForCountry as $timeZone) { if (TimeZone::isTimeZone($timeZone)) { $value = TimeZone::findByFullName($timeZone); $timezoneArray[] = convertTimezoneToArray($timeZone, $value); } } return $timezoneArray; } $inputArray = ["Asia/Yekaterinburg", "Europe/Kaliningrad", "Europe/Moscow", "Europe/Samara"]; convertTimezoneList($inputArray);
Output for 7.0.0 - 7.0.2
Fatal error: Cannot use "self" when no class scope is active in /in/Hk4vm on line 16
Process exited with code 255.
Output for 5.5.24 - 5.5.31, 5.6.8 - 5.6.17
Fatal error: Class 'TimeZone' not found in /in/Hk4vm on line 27
Process exited with code 255.

preferences:
152.26 ms | 1395 KiB | 28 Q