i have an array. i want to sum all time in the array so it will result sum of all time in the array. :
//print_r($chart_average);
Array ( [0] => 00:20:00 [1] => 00:03:45 [2])
how to sum all the time in array above and show result like below. How to calculate all array?
total time : 00:23:45
my answer for my reference after this :
foreach ($chart_average as $time) {
list($hour, $minute, $second) = explode(':', $time);
$all_seconds += $hour * 3600;
$all_seconds += $minute * 60;
$all_seconds += $second;
}
$total_minutes = floor($all_seconds/60);
$seconds = $all_seconds % 60;
$hours = floor($total_minutes / 60);
$minutes = $total_minutes % 60;
// returns the time already formatted
echo sprintf('%02d:%02d:%02d', $hours, $minutes,$seconds);