PHP average time from an array

后端 未结 4 480
逝去的感伤
逝去的感伤 2021-01-18 18:48

How do I work out the average time from an array of times.

I have an array that looks like this :

(\'17:29:53\',\'16:00:32\')

And I

4条回答
  •  心在旅途
    2021-01-18 19:23

    $times = array('17:29:53','16:00:32');
    
    $totaltime = '';
    foreach($times as $time){
            $timestamp = strtotime($time);
            $totaltime += $timestamp;
    }
    
    $average_time = ($totaltime/count($times));
    
    echo date('H:i:s',$average_time);
    

提交回复
热议问题