晚上好
我在这里有个问题。我有两个数组:$duration_c[$k][$s]。一切正常
$duration_c[0][0]="19:30:00";
$duration_c[0][1]="00:10:00";
$duration_c[1][0]="00:30:00";
$duration_c[1][1]="00:20:00";
比总和
$times=$duration_c[$k][$s];
function sum_the_time($times) {
$seconds = 0;
foreach ($times as $time)
{
list($hour,$minute,$second) = explode(':', $time);
$seconds += $hour*3600;
$seconds += $minute*60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours*3600;
$minutes = floor($seconds/60);
$seconds -= $minutes*60;
// return "{$hours}:{$minutes}:{$seconds}";
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
}
echo sum_the_time($times);
$duration_c[0][0]+$duration_c[0][1] 和 $duration_c[1][0]+$duration_c[1][1] 如何求和,如何打印?为 foreach() 提供了错误无效参数