PHP Snippet 2:
for ($i = 0; $i < count($array); $i++) { //array contains your sorted times like [H:i]
$a = $array[$i]. " " .date("Y/m/d");
$array[$i] = $a;
}
$total=0;
for ($i = count($array); $i>1; $i--){
if ($array[$i-1] < $array[$i-2]){
$array[$i-1] = strtotime("+1 day", strtotime($array[$i-1]));
$z = "a";
}
$a = strtotime($array[$i-1]);
$b = strtotime($array[$i-2]);
$diff = $a - $b;
$hours = ceil($diff / (24*60));
$total += date("H", $hours);
}
if ($z == "a"){
$total += date("H", ceil(strtotime($array[0]) / (24*60)));
}