计算小时和分钟 PHP 数组的总和



为此苦苦挣扎!

我需要 php 中所有差异的总和,所以这里是源代码

$du = mysql_query("select SUBTIME(timeto,timefrom) as diff from table");
while($d = mysql_fetch_assoc($du))
{
    $total[] = strtotime($d["diff"]);
}
$t = array_sum($total);
echo gmdate("H:i", $t);

在你说之前... 我知道我应该使用 PDO 或 mysqli

不幸的是,我需要PHP中的解决方案

$du = mysql_query("SELECT SUM(TIME_TO_SEC(TIMEDIFF(timeto, timefrom))) AS TOTAL_SEC FROM table");
$d = mysql_fetch_assoc($du);
echo gmdate("H:i", $d["TOTAL_SEC"]);

最新更新