I have an session cookie holding a multidimensional array called cart_array and I'm using a for each to loop through the inner arrays and a while loop get the key value pairs out.
I want to check if an item exists in the array based not only on the product id (pid) but several other variables such as color and size. Here's what I've come up with so far (but it only checks for the pid). How can I check for the other two variables?
Here are my variables
$_SESSION['cart_array'] = array(1 => array(
"pid" => $pid,
"quantity" => $quantity,
"color" => $color,
"size" => $size,
"title" => $title,
"product_type" => $product_type,
"price" => $price))
Here is the code for and while loop combination:
foreach($_SESSION['cart_array'] as $each_item) {
$index++;
while(list($key, $value) = each($each_item)) {
if($key == "pid" && $value == $pid) {
//That item is in the array
echo "This item is in the array";
} else {
echo "This item is not in the cart";
}
}
}