Hi, now I've a function which is add product to cart:

    function addtocart($pid,$q,$attribute){
        if($pid<1 or $q<1) return;

        if(is_array($_SESSION['cart'])){

            $max=count($_SESSION['cart']);
            $_SESSION['cart'][$max]['productid']=$pid;
            $_SESSION['cart'][$max]['qty']=$q;
            $_SESSION['cart'][$max]['attribute']=$attribute;
        }
        else{
            $_SESSION['cart']=array();
            $_SESSION['cart'][0]['productid']=$pid;
            $_SESSION['cart'][0]['qty']=$q;
            $_SESSION['cart'][0]['attribute']=$attribute;
        }
    }

And now my remove product function is :

$id is generate from for loop in cart page which is same value with $i below

    function remove_product($id){
        $id=intval($id);
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){

            (This part how to determine $_SESSION['cart'][$i] that match with $id)?

                unset($_SESSION['cart'][$i]);
                break;
            }
            if($_SESSION['cart'] == ''){
            unset($_SESSION['cart']);   
            }
        }
        $_SESSION['cart']=array_values($_SESSION['cart']);
    }

my previous code is :

if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;

but now I don't want to determine productid , I want to determine the number $i that pass from my cart page and remove the item. Any solution?

Member Avatar for LastMitch

but now I don't want to determine productid , I want to determine the number $i that pass from my cart page and remove the item. Any solution?

@devianleong

Even before we start assisting you. You have to be very honest with us. Where did you get this code? Are you using a platform like Magento or Prestoshop? If so you are trying to modify the file? If you did created this code, you should know there is a by pass and so far the code you provided doesn't show any sign of it. You need to post a code related to that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.