购物车问题

I have this shopping cart

function modifyCart($action, $id){

$kori = cart();
$exp = explode("|", $kori);

for($i=0;$i<count($exp);$i++){
$pilk = explode("-", $exp[$i]);
if($id == $pilk[0]){
    switch($action){
        case "increase": // lisätään määrää
        break;

        case "decrease": // vähennetään määrää
        break;

        case "remove": // poistetaan
        unset($exp[$i]);
    }
 }
}

$valmis = array_merge($exp, $pilk);

$muuta  = implode("|", $valmis);

$_SESSION["cart"] = $muuta;


}

Cart is stored like productno-qty|productno-qty How could i get the function to work.. thank for helping

That's a terrible cart. But if you are stuck on this track, you want this:

function modifyCart($action, $id){

$kori = cart();
$exp = explode("|", $kori);

foreach ($key, $product in $exp) {
    $tmp = explode('-', $product);
    $productNo = $tmp[0];
    $productQty = $tmp[1];

    if ($id == $productNo) {
        if ($action == 'remove') {
            unset($exp[$key]);
            return implode('|', $exp);
        } else if ($action == 'increase') {
            $productQty += 1;
            $exp[$key] = $productNo . '-' $productQty;
            return implode('|', $exp);
        } else if ($action == 'decrease') {
            $productQty -= 1;
            if ($productQty == 0) {
                unset($exp[$key]);
            } else {
                $exp[$key] = $productNo . '-' $productQty;
            }
            return implode('|', $exp);
        } else {
            // throw exception because unrecognized action
        }
    }
    // handle case where named product was not in the cart here.
    return implode('|', $exp);
}