calculating subtotal and total from basic shopping cart script
<p>Im trying to calculate a subtotal and a total from a series of values stored in an array returned from a mysql database.</p>

<p>this i what i have thusfar</p>

<pre><code> while($row = mysql_fetch_array($cart)){ 
 foreach($row AS $key =&gt; $value) { $row[$key] = stripslashes($value); } 
 $id = $row['id'];
 $contents = unserialize($row['contents']);
  foreach( $contents as $key =&gt; $value){
   if($key == "price"){$subtotal = $subtotal+$value;}
   echo "$key : $value &lt;br /&gt;";
  }
 echo "&lt;br&gt;&lt;br&gt;&lt;br&gt;";
 } 
echo "&lt;font color=red&gt;SubTotal $subtotal&lt;/font&gt;";
</code></pre>

<p>$contents contains an array <code>[name] =&gt; super [price] =&gt; 65.87 [quantity] =&gt; 25</code></p>

<p>So i need to multiply the price by quantity, and then take that subtotal (per item) and add it in total after the loop</p>
