3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $countryName = false; $tzList = array(); $tzList[54] = array('name' => 'Moscow, St. Petersburg, Volgograd', 'tz' => 'Europe/Moscow', 'country' => array('RU')); $timeZoneDataId = array(); $timeZoneDataJs = array(); $timeZonesystemName = array(); $year = date('Y'); foreach ($tzList as $key => $tz) { $temp = array(); try { $dateTimeZone = new DateTimeZone($tz['tz']); $dateTimeWinter = new DateTime($year . "-1-1", $dateTimeZone); $dateTimeSummer = new DateTime($year . "-6-30", $dateTimeZone); $dateNow = new DateTime("now", $dateTimeZone); $temp['n'] = $tz['name']; $temp['n'] = $key; if ($countryName && in_array($countryName, $tz['country'])) { $temp['c'] = 1; } $temp['o'] = $dateTimeZone->getOffset($dateNow) / 3600; $summerOffset = $dateTimeZone->getOffset($dateTimeSummer); $winterOffset = $dateTimeZone->getOffset($dateTimeWinter); $nowOffset = $dateTimeZone->getOffset($dateNow); $timeZoneDataId[$tz['tz']] = $key; $timeZoneDataJs[$summerOffset][$winterOffset][] = $temp; $timeZonesystemName[$key] = $tz['tz']; //add info to tzList $tzList[$key]['offsetNow'] = $nowOffset / 3600; $tzList[$key]['id'] = $key; } catch (Exception $e) { //echo '*' . $tz['tz'] . '*'; } } echo $tzList[54][$countryName ];
based on 8aNTC
Output for 7.0.0 - 7.1.0
Notice: Undefined offset: 0 in /in/L7WnS on line 41
Output for 5.3.0 - 5.6.28
Notice: Undefined offset: 0 in /in/L7WnS on line 42
Output for 5.2.0 - 5.2.17
Notice: Undefined offset: 0 in /in/L7WnS on line 42
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTimeZone' not found in /in/L7WnS on line 14
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/L7WnS on line 13
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/L7WnS on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/L7WnS on line 13
Process exited with code 255.