Your problem lies precisely in the function gmdate, as it will format a date from a timestamp (Unix Epoch). As in the example below:
gmdate("d/m/Y h:i:s", '1000000'); // 12/01/1970 01:46:40
You could add/divide/multiply the time you’ve already calculated to get to the final time. However, I don’t really like this annoyance, as it leaves aside what PHP has internally already implemented.
In this case, PHP has a specific class to work with time/date intervals, which is the class Dateinterval. However, it is not so trivial to work it for your specific case, because natively you cannot add one Dateinterval to another.
Another detail is the format that Dateinterval needs to be created, which is different from the traditional date format (let’s say so).
On the other hand, you can use the Datetime class together, which helps us to create a Dateinterval without changing the format from the database.
//é necessária uma data base (00:00:00) - $baseDate
//e uma data para adicionar/somar os tempos vindos do SGBD - $date
$baseDate = clone $date = \DateTime::createFromFormat('H:i:s' , '00:00:00');
//dados vindo do banco de dados
$array = [
'04:30',
'05:30',
'04:23',
'02:35',
'01:50',
'03:25',
'03:40',
'02:30'
];
//percorre cada valor do array
foreach($array as $time)
{
//cria-se o date time com o tempo informado
$dateTime = \DateTime::createFromFormat('H:i' , $time);
//realiza o diff com a $baseDate para criar o DateInterval
$diff = $baseDate->diff($dateTime);
//adiciona o diff ao DateTime que somará o tempo
$date->add($diff);
}
//realiza o último diff entre o DateTime de soma e a base date
$interval = $baseDate->diff($date);
//DateInterval mantêm em dias (%a) tudo que for acima de 24 horas.
$hours = $interval->format('%H') + ($interval->format('%a') * 24);
//exibe o tempo
echo $hours.$interval->format(':%I'); // Saída: 28:23
The code was a little extended by the explanation, however, ends up using objects that can be reused for display and other calculations when necessary.