PHP Add up a series of minutes:seconds

Dfdkjrvescpuu

New Member
I have a list of video segment durations I need to add up to get the total duration.The series is like this:
  • 0:33
  • 4:30
  • 6:03
  • 2:10
...etcI need to add up the minutes and seconds to get a total video duration.Here's the modified function of my accepted answer:\[code\]function getTotalDuration ($durations) { $total = 0; foreach ($durations as $duration) { $duration = explode(':',$duration); $total += $duration[0] * 60; $total += $duration[1]; } $mins = floor($total / 60); $secs = str_pad ( $total % 60, '2', '0', STR_PAD_LEFT); return $mins.':'.$secs;}\[/code\]Just made sure the output looks correct.
 
Back
Top