I have a kind of store where members of a ski club can rent equipment. The first step is a loop where the member can make repetitive choices, for example for him and his family. Each line of material has its own total with a grand total at the bottom. A problem occurs once the last renting has been done and the member want to finalize his payment. The line of the last rented equipment is doubled and as a result the grand total is false. An idea how to solve this. I think it has something to do with my UNSET instruction. Thanks for helping. Here is the code of my foreach loops:
foreach ($price as $key => $value) {
$number[$key] = str_pad($number[$key], 2);
$type[$key] = str_pad($type[$key], 21);
$lenght[$key] = str_pad($lenght[$key], 15);
$boots[$key] = str_pad($boots[$key], 22);
$size[$key] = str_pad($size[$key], 15);
$priceskipers[$key] = ($priceski[$key]) * ($person[$key]);
$pricebootspers[$key] = ($priceboots[$key]) * ($person[$key]);
$total[$key] = array_sum(array($priceskipers[$key], $pricebootspers[$key]));
$supertotal = 0;
$id++;
echo "<pre>Data : " .$date[$key] . " | " . $number[$key] . " / " . $person[$key] . "| " . $type[$key] . " | " . $lenght[$key] . " | " . $boots[$key] . " | " . $size[$key] . "<br> " . $priceskipers[$key] . " + " . $pricebootspers[$key] . " = " . $total[$key] . " for this reservation (id" . $id . ").<hr></pre>";
unset($value);
foreach ($total as $key2 => $value2) {
$supertotal += $total[$key2];
$discount = (($supertotal) * 0.2);
$grandtotal = (($supertotal) - ($discount));
}
}
echo "<pre><b>Total " . $supertotal . " - 20% (discount for online renting) " . $discount . " = " . $grandtotal . ", your net amount.</b></pre>";