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?