Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function somarHoras(array $times) {
- $seconds = 0;
- foreach ($times as $time) {
- list( $g, $i, $s ) = explode(':', $time);
- $seconds += $g * 3600;
- $seconds += $i * 60;
- $seconds += $s;
- }
- $hours = floor($seconds / 3600);
- $seconds -= $hours * 3600;
- $minutes = floor($seconds / 60);
- $seconds -= $minutes * 60;
- $seconds = ($seconds == 0 || $seconds <= 9) ? "0{$seconds}" : $seconds;
- $minutes = ($minutes == 0 || $minutes <= 9) ? "0{$minutes}" : $minutes;
- $hours = ($hours <= 9) ? "0{$hours}" : $hours;
- return "{$hours}:{$minutes}:{$seconds}";
- }
- $times = [
- '01:31:22',
- '03:29:38',
- ];
- echo somarHoras($times);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement