Ver Mensaje Individual
  #9 (permalink)  
Antiguo 30/03/2019, 16:40
desdeferrol
 
Fecha de Ingreso: noviembre-2011
Ubicación: Ferrol
Mensajes: 11
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: suma de array de horas

Funciona perfectamente, muchas gracias a todos.

<?php
$soloHoras =[];

foreach($planificador as $valor) {
array_push($soloHoras, $valor['tiempo']);
}

function sumarHoras($horas) {
$total_horas = 0;
foreach($horas as $h) {
$parts = explode(":", $h );
@$total_horas += $parts[2] + $parts[1]*60 + $parts[0]*3600;
}
$h = sprintf('%02d',floor($total_horas / 3600)); // Calculas horas
$total_horas -= $h * 3600; // Restas al total
$m = sprintf('%02d',floor($total_horas / 60)); // Calculas minutos
$s = sprintf('%02d',$total_horas - ($m * 60)); // Calculas segundos restando minutos al total // Calculas segundos restando minutos al total
return $h . ':' . $m . ":" . $s;
}
echo sumarHoras ($soloHoras);
?>