3v4l.org

run code in 300+ PHP versions simultaneously
<?php const TIME_ZONE_FORMAT_NAME = 'utc'; $KEY_VALUE = 'value'; $KEY_NAME = 'name'; $KEY_OFFSET = 'offset'; $KEY_FORMAT = 'format'; $KEY_DISPLAY = 'display'; function convertTimezoneToArray($timezone, $value) { $dateTime = new \DateTime(); $dateTime->setTimeZone(new \DateTimeZone($timezone)); return [ $KEY_VALUE => $value, $KEY_NAME => $timezone, $KEY_OFFSET => $dateTime->format('P'), $KEY_FORMAT => $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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Class "TimeZone" not found in /in/QXYi1:27 Stack trace: #0 /in/QXYi1(38): convertTimezoneList(Array) #1 {main} thrown in /in/QXYi1 on line 27
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'TimeZone' not found in /in/QXYi1:27 Stack trace: #0 /in/QXYi1(38): convertTimezoneList(Array) #1 {main} thrown in /in/QXYi1 on line 27
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Class 'TimeZone' not found in /in/QXYi1 on line 27
Process exited with code 255.

preferences:
216.45 ms | 402 KiB | 228 Q