// try it at: http://kanzie.com/bgc/rpc.php?mode=addCart&productid=14,15,16,14,14,15,14
if ($_GET['mode'] == "addCart") {
if (isset($_GET['productid'])) {
$products = explode(",",$_GET['productid']);
var_dump($products);
if (isset($products)) {
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
echo "
SESSION Cart not set, setting it
";
}
foreach ($products as $key) {
if (array_key_exists($key,$_SESSION['cart'])) {
$_SESSION['cart'][$key]++;
echo "Key " . $key . " exists, incrementing value, value now " . $_SESSION['cart'][$key] . "
";
} else {
$_SESSION['cart'] = array($key => 1);
echo "no previous key for " . $key .", setting value 1
";
}
} // for every productid in productid-POST
} // no products set in the products= POST
} // productid-POST is not set
} // mode is not "addCart"
echo("
");
print_r(array_values($_SESSION['cart']));