3v4l.org

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