3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on Hk4vm
Output for 7.0.0 - 7.2.0
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.4.11 - 5.6.28
Fatal error: Class 'TimeZone' not found in /in/QXYi1 on line 27
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/QXYi1 on line 15
Process exited with code 255.