3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $empty = new DateTime('00:00:00'); $inside = clone $empty; $outside = clone $empty; $rows = [ ['date' => '10.06.2015', 'time' => '10:12:42', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '10:27:48', 'enter-exit' => 0], ['date' => '10.06.2015', 'time' => '10:30:28', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '12:28:06', 'enter-exit' => 0], ['date' => '10.06.2015', 'time' => '12:30:17', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '13:49:41', 'enter-exit' => 0], ['date' => '10.06.2015', 'time' => '14:04:56', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '14:57:06', 'enter-exit' => 0], ['date' => '10.06.2015', 'time' => '15:11:13', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '16:14:14', 'enter-exit' => 0], ['date' => '10.06.2015', 'time' => '19:10:21', 'enter-exit' => 1], ['date' => '10.06.2015', 'time' => '19:21:38', 'enter-exit' => 0], ]; foreach ($rows as $row) { $datetime = $row['date'] . ' ' . $row['time']; $datetime = DateTime::createFromFormat('d.m.Y H:i:s', $datetime); if ($row['enter-exit']) { $enter = $datetime; if (isset($exit)) { $interval = $enter->diff($exit); $outside->add($interval); } } else { $exit = $datetime; if (isset($enter)) { $interval = $exit->diff($enter); $inside->add($interval); } } } echo 'В офисе: ' . $empty->diff($inside)->format('%h:%I:%S') . '<br>'; echo 'Вне офиса: ' . $empty->diff($outside)->format('%h:%I:%S');
based on fjlTW
Output for 5.4.0 - 7.3.0rc4
В офисе: 5:38:36<br>Вне офиса: 3:30:20
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Rorl2 on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Rorl2 on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/Rorl2 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/Rorl2 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Rorl2 on line 4
Process exited with code 255.