如何在CodeIgniter中获取所有total_duration
的总和。
Array
(
[caller] => Ravneet Kaur
[total_calls] => 1
[total_duration] => 00:00:06
)
Array
(
[caller] => Navneet Kaur
[total_calls] => 2
[total_duration] => 00:00:19
)
Array
(
[caller] => Jasmeet Kaur
[total_calls] => 0
[total_duration] => 00:00:00
)
Array
(
[caller] => sunny Kumar
[total_calls] => 0
[total_duration] => 00:00:00
)
答案 0 :(得分:0)
此answer可能有助于在array_column
检查一下:
$total = array_column($array, 'total_duration');
$sum = strtotime('00:00:00');
$sum2=0;
foreach ($total as $v){
$sum1=strtotime($v)-$sum;
$sum2 = $sum2+$sum1;
}
$sum3=$sum+$sum2;
echo date("H:i:s",$sum3);
答案 1 :(得分:0)
这是持续时间的总和
$seconds= 0;
foreach ($new_arr as $key => $value) {
list($hour,$minute,$second) = explode(':',$value["total_duration"]);
$seconds += $hour*3600;
$seconds += $minute*60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours*3600;
$minutes = floor($seconds/60);
$seconds -= $minutes*60;
echo sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
你可以在这里查看答案=> https://eval.in/592792
希望这个答案可以帮到你