php - calculate price multiplied by quantity for several items to get individual totals and a grand total
<p>I have a form that has 7 different items. The user will be able to input quantity (unlimited) and the price will be set for each item (let's say for example, item 1 is $18, and item 2 is $20, etc.). What I have done with another form that's almost identical is this:</p>

<pre><code>if(!empty($_POST[qty_item_1])) {
    $total_1 = ($_POST[qty_item_1] * 18);
} else {
$total_1 = "0";
}

if(!empty($_POST[qty_item_2])) {
$total_2 = ($_POST[qty_item_2] * 20);
} else {
$total_2 = "0";
}
</code></pre>

<p>I would have a code block like those for each item. It seems to work fine but I feel like this is probably the hard way to do it but I'm having trouble figuring out what else I might do. Any suggestions?</p>
