I have an array being set into $_SESSION["cart_array"] and the output is as such when items are in the cart.
Array ( [0] => Array ( [item_id] => 1 [quantity] => 6 ) [1] => Array ( [item_id] => 2 [quantity] => 1 ) )
I am trying to create a foreach loop to go through and count up the "quantity" values as to get a total cart item count, so far i have the below but i just cannot figure out how to get it into a string variable so i can display it on other pages.
$cartCount = array();
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartCount = 0;
} else {
foreach ($_SESSION["cart_array"] as $each_item) {
//$cartCount += $each_item['quantity']; <-- commented out as not working.
//$cartCount[$each_item['item_id']] += $each_item['quantity']; <-- commented out as not working.
}
//Print array for debugging purposes
print_r($_SESSION["cart_array"]);
}