i was wondering this is a very basic and probably stupid question. i am sorry for that.
how do i sum up the values of a calculated array. i want to get the sum of sub totals as grand total in php. following is the code
if(count($_POST))
{
$len = count($_POST['item']);
for ($i=0; $i < $len; $i++)
{
echo "<tr><td>";
echo $_POST['item'][$i] . '<br>';
echo "</td><td>";
echo $_POST['qty'][$i] . '<br>';
echo "</td><td>";
echo $_POST['price'][$i] . '<br>';
echo "</td><td>";
$tv = ($_POST['qty'][$i]*$_POST['price'][$i]);
echo $tv;
echo "</td></tr>";
}
}
echo "</table>";
I am receiving Item,Quantity,Price from the previous form (variable no of rows)
now i have been able to calculate and echo out the sub totals($tv). but facing problems in calculating the grand total.
grand total = sum of all $tv
Basics 🙂