$products[$key]['name'], 'cost' => $cost, 'qty' => $quantity, 'total' => $total ); $_SESSION['cart12'][$key] = $item; } // Update an item in the cart function update_item($key, $quantity) { global $products; $quantity = (int) $quantity; if (isset($_SESSION['cart12'][$key])) { if ($quantity <= 0) { unset($_SESSION['cart12'][$key]); } else { $_SESSION['cart12'][$key]['qty'] = $quantity; $total = $_SESSION['cart12'][$key]['cost'] * $_SESSION['cart12'][$key]['qty']; $_SESSION['cart12'][$key]['total'] = $total; } } } // Get cart subtotal function get_subtotal() { $subtotal = 0; foreach ($_SESSION['cart12'] as $item) { $subtotal += $item['total']; } $subtotal = number_format($subtotal, 2); return $subtotal; } ?>