I have a foreach loop that adds all lines from a table with dynamic rows (add row for every new product you want in the order from previous page - sometimes it could be 3 Products, sometimes it could be 23 Products) that creates a pdf purchase order (using mpdf). I'm not having any problem with the line items showing (Product x Quantity = Total) cost for each line. My issue is getting those totals into a single Total cost at the bottom of the Purchase order.
Example on the PDF created:
Product 1 $2 x 3 = $6
Product 2 $4 x 2 = $8
Product 3 $6 x 1 = $6
All that works correctly. Here is the code for the foreach loop.
<?php
foreach ($product as $a => $b) {
$prod_cost1[$a] = (("$qty[$a]") * ("$prod_cost[$a]"));
echo "
<tr>
<td>$product[$a] </td>
<td>$qty[$a] </td>
<td>$prod_cost1[$a] </td>
</tr>";
}
?>
I just somehow need to total all the $prod_cost1 and be able to display that somewhere on the page. Thank you for your help!
array_sum($prod_cost1)