<?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');