math - PHP Add up a series of minutes:seconds -


i have list of video segment durations need add total duration.

the series this:

  • 0:33
  • 4:30
  • 6:03
  • 2:10

...etc

i need add minutes , seconds total video duration.


here's modified function of accepted answer:

function gettotalduration ($durations) {     $total = 0;     foreach ($durations $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; } 

just made sure output looks correct.

give code shot:

function gettotalduration ($durations) {     $total = 0;     foreach ($durations $duration) {         $duration = explode(':',$duration);         $total += $duration[0] * 60;         $total += $duration[1];     }     $mins = $total / 60;     $secs = $total % 60;     return $mins.':'.$secs; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -