I am using session variables to keep track of what is in a shopping cart. I can add the items to the cart quite easily enough. But my problem is that I can't delete a specific item in the cart. Below is a summary of what the array looks like
$Item1=array("ProdID"=>"Hat","Color"=>"Not Needed","Size"=>5);
$Item4=array("ProdID"=>"Shirt","Color"=>"Green","Size"=>"L");
$Item2=array("ProdID"=>"Pants","Color"=>"Not Needed","Size"=>"32x32");
$Item3=array("ProdID"=>"Socks","Color"=>"Not Needed","Size"=>"Not Needed");
$NumItems=4;
$TestArray=array("NumItems"=>$NumItems,1=>$Item1,2=>$Item2,3=>$Item3,4=>$Item4);
However when I attempt to delete any of the top level elements (1,2,3,4,NumItems), I either end up deleting only the last element (4) or somehow taking out 2 of them. I know that this must be an easy fix but I've looked at it for so long that I can't seem to figure out what the problem is.
below is the code that I use to delete the Item from the array
$ItemNum=$_GET['item'];
if ($ItemNum=="All"){
$ItemNum=$_GET['item'];
if ($ItemNum=="All"){
unset($TestArray);
unset($TestArray['NumItems']);
unset($_SESSION['OrderTotal']);
//header("Location:Cart.php?act=view");
}
else{
$TestArray['NumItems']=$TestArray['NumItems']-1;
if($TestArray['NumItems']<1)
{
unset($_SESSION['OrderTotal']);
unset($TestArray);
unset($TestArray['NumItems']);
}
else
{
unset($TestArray[$ItemNum]);
}
Can anyone take a look at this and point me in the correct direction? What I am after is to delete any element of the top array and keep the rest.