总和列:还款时间表
#php #帮助

如何获得每个单独的列的总和。适当的本金,利息和每月总付款,使用循环。我希望结果在表下方的(-----------)部分中输出。有帮助吗?

<h1>Loan Repayment Schedule</h1>
<p><b>Amount Taken:</b> 1,000,000</p>
<p><b>Period:</b> 12 Months</p>
<p><b>Interest:</b> 2 %</p>
<table border="1">
  <thead>
    <tr>
      <th>Month</th>
      <th>Due Date</th>
      <th>Description</th>
      <th>Due Principal</th>
      <th>Interest</th>
      <th>Total Monthly Payment</th>
      <th>Principal Balance</th>
    </tr>
  </thead>
  <tbody>
    <?php
      $balance = 1000000;
      $period = 12;
      $emi = $balance/$period;
      $payment_date = date('2022-09-28');

      for ($i=1; $i <=$period; $i++){
        $interest = ((2/100)*$balance);
        $principal = $emi +$interest;
        $balance = $balance - $emi;
        $payment_date = date("jS F, Y",strtotime("+1 month",strtotime($payment_date)));
        ?>
          <tr>
            <td><?php echo $i;?></td>
            <td><?php echo $payment_date;?></td>
            <td>Repayment</td>
            <td><?php echo number_format($emi);?></td>
            <td><?php echo number_format($interest);?></td>
            <td><?php echo number_format($principal);?></td>
            <td><?php echo number_format($balance);?></td>
          </tr>
        <?php
      }
    ?>
  </tbody>
  <tfoot>
    <tr>
      <th></th>
      <th></th>
      <th></th>
      <th>-----------</th>
      <th>-----------</th>
      <th>-----------</th>
      <th></th>
    </tr>
  </tfoot>
</table>