Reading cookies into arrays results wrong in chrome and opera while it is right firefox
===

I am trying to build a shopping cart for my website and I have ran into a problem. 

I am storing product Ids, quantities and comments as cookie arrays, then reading them into php and javascript arrays for visualization. When the user adds a product that already exists in the cart, I update the cookie holding the quantity of the product by adding the new value to the old value and storing it to the same cookie. Same goes with comments for a product that already exists in the cart, I concat them and store them together in the same cookie.

In firefox everything works perfect, in opera and chrome, when I add a product that already exists, something gets messed up with the array indexes and different quantities get matched to different IDs, etc.

Here is the part of my code that handles the cookies and the arrays.


    //store productIds into php array
    if (isset($_COOKIE['productIds'])) 
    {			
    	$cookiesSet = array_keys($_COOKIE['productIds']);
    	$cookieValues = array_values($_COOKIE['productIds']);
    	for ($c = 0; $c < count($cookiesSet); $c++) {
    		$value = $cookieValues[$cookiesSet[$c]];
    		$productIds[$c] = $value;
    	}
    }
    //store product quantities into php array
    if (isset($_COOKIE['productQties'])) 
    {
    	$cookiesSet = array_keys($_COOKIE['productQties']);
    	$cookieValues = array_values($_COOKIE['productQties']);
    	for ($c = 0; $c < count($cookiesSet); $c++) {
    		$value = $cookieValues[$cookiesSet[$c]];
    		$productQties[$c] = $value;
    	}
    }
    //store product messages into php array
    if (isset($_COOKIE['productComs'])) 
    {
    	$cookiesSet = array_keys($_COOKIE['productComs']);
    	$cookieValues = array_values($_COOKIE['productComs']);
    	for ($c = 0; $c < count($cookiesSet); $c++) {
    		$value = $cookieValues[$cookiesSet[$c]];
    		$productComs[$c] = $value;
    	}
    }
    
    if ((isset($_GET['productId'])) && (isset($_GET['quantity'])) && (isset($_GET['comments']))){
    	$in30days = time()+60*60*24*30;
    	$emptyComment = "χωρίς σχόλιο";
    	
    	if(!in_array($_GET['productId'], $productIds)){
    		setcookie('productIds[' . sizeof($productIds) . ']', $_GET['productId'],  $in30days);
    		setcookie('productQties[' . sizeof($productQties) . ']', $_GET['quantity'],  $in30days);
    		if($_GET['comments']!=null){
    			setcookie('productComs[' . sizeof($productComs) . ']', $_GET['comments'],  $in30days);
    		}
    		else{
    			setcookie('productComs[' . sizeof($productComs) . ']', $emptyComment,  $in30days);
    		}
    		
    	}
    	else{
    		for($i=0;$i<sizeof($productIds);$i++){
    			if($productIds[$i]==$_GET['productId']){
    				$productQties[$i]+=$_GET['quantity'];
    				setcookie('productQties[' . $i . ']', $productQties[$i],  $in30days);
    				if($productComs[$i]!=$emptyComment){
    					if($_GET['comments']!=null){
    						$newcomment = $productComs[$i] . "<br />-----------------<br />" .  $_GET['comments'];
    						setcookie('productComs[' . $i . ']', $newcomment,  $in30days);
    					}
    				}
    				else{
    					if($_GET['comments']!=null){
    						setcookie('productComs[' . $i . ']', $_GET['comments'],  $in30days);
    					}
    					else{
    						setcookie('productComs[' . $i . ']', $emptyComment,  $in30days);
    					}
    				}
    			}
    		}
    	}
    	header("location: cart.php");
    }