テーブルを印刷するには、最終的な配列として準備された配列を使用して、次のようにすることができます
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<h1>Customer Ledger(<?php echo $rearrangedFinalData[0]['customer'] ?>)</h1>
<table>
<tr>
<td>Date</td>
<td>Invoice No</td>
<td>Debit</td>
<td>Credit</td>
<td>Balance</td>
</tr>
<?php
//initialize balance as per your requirement
$balance = 0;
foreach($rearrangedFinalData AS $row) {
?>
<tr>
<td><?php echo $row['date'] ?></td>
<td><?php echo $row['invoice'] ?></td>
<td><?php echo $row['debit'] > 0 ? $row['debit'] : '' ?></td>
<td><?php echo $row['credit'] > 0 ? $row['credit'] : '' ?></td>
<td><?php echo $balance = ($balance + $row['debit'] - $row['credit']) ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>