foreach,sum和table(noob)很难

I have a table that is created by my billing manager. It has a foreach that inserts the calls in the table that list it, pretty simple.

I have as a task from my boss to include on the bottom of the table the sum of all call durations, which is an item from it, but doesn't appear as a sum.

After some hours, I surrendered to my ignorance. I guess the easiest way should be to put on this (resumed) section to include the value on an array:


foreach ($this->call_list as $id => $callsList): ?>

<td class="text-center"><?php echo $this->format->fmt_segundos(array("a" => $callsList['billsec'], "b" => 'hms')); ?></td>

<?php endforeach?>

And then, down here, I would put the code to sum all the values on that variable:


<td class="text-center"><?php echo $this->translate("Duration") ?> <?php echo "<br>"; ?>  <label class="label label-info"><?php echo $this->totals['tempo']; ?></label></td>

But I don't know how. Could you guys help me?

I don't know spanish but i assume that function, fmt_segundos returns duration in seconds. In this case, the following code should do the trick:

<table>
   <thead>
      <td>id</td><td>Duration</td>
   </thead>
<?php
   $TOTAL= 0;
   foreach ($this->call_list as $id => $callsList){ 
      $a = $this->format->fmt_segundos(array("a" => $callsList['billsec'], "b" => 'hms'));
      $TOTAL += $a;
      echo '<tr>';
      echo '<td class="text-center">'.$id.'</td>';
      echo '<td class="text-center">';
      echo gmdate("H:i:s", $a); 
      echo '</td>';
      echo '</tr>';
   }
?>
    <tfoot>
        <td>TOTAL</td><td><?=gmdate("H:i:s",$TOTAL)?></td>
    </tfoot>
</table>