PHP数组,表,形式,乘法... argh

I have tried for hours, and hope you can help me now :

I am trying to get values from a HTML form via $_POST into a table via PHP, and multiplying two numbers: ['amount'] * ['price'] = $totalprice

So far so good.

I get something that might look like this:

Description – Amount – Format – Price – Total ($totalprice)

Spoon – 3 – pieces – 4 – 12

Plate – 2 – pieces – 3 – 6

Glass – 6 – pieces – 3 – 18

Now how do I sum up all the “Total” ($totalprice)’s 12+6+18 so I get the result: 36 ?

The piece of code I’m struggling with:

foreach($_POST['description'] as $value)
{
echo "<tr><td>";
echo $i+1;
echo "</td>
<td>".$value."</td>
<td><center>".$_POST['amount'][$i]."</td>
<td><center>".$_POST['format'][$i]."</td>
<td><center>".$_POST['price'][$i]."</td>";

//Figures out the total price = amount * price
$x1 = $_POST['amount'] [$i];
$x2 = $_POST['price'] [$i];
echo "<td><center>";
$totalprice = $x1 * $x2;
echo $totalprice;
//Figures out the total price = amount * price

$i++;
}

You just need to sum all totals while iterating

$grand_total = 0;
foreach($_POST['description'] as $value)
{
    echo "<tr><td>";
    // code here...

    $totalprice = $x1 * $x2;
    echo $totalprice;

    $grand_total = $grand_total + $totalprice;
    $i++;
}
echo $grand_total;

use this code

$totalprice = 0;
foreach($_POST['description'] as $value)
{
    echo "<tr><td>";
    echo $i+1;
    echo "</td>
    <td>".$value."</td>
    <td><center>".$_POST['amount'][$i]."</td>
    <td><center>".$_POST['format'][$i]."</td>
    <td><center>".$_POST['price'][$i]."</td>";

    //Figures out the total price = amount * price
    $x1 = $_POST['amount'] [$i];
    $x2 = $_POST['price'] [$i];
    echo "<td><center>";
    $totalprice = $totalprice + ($x1 * $x2);
    $i++;
}
echo $totalprice;