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 git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.03 ms | 401 KiB | 8 Q