seaweed Posted June 25, 2010 Share Posted June 25, 2010 Can anyone point out why this isn't incrementing the qty of items already in the cart? Maybe it's a Friday Brain Fart... session_start(); if (isset($_SESSION['CART']) == false || isset($_SESSION['CART']['ITEMS']) == false) { $_SESSION['CART']['ITEMS'] = array(); } foreach ($_POST AS $sku => $qty) { if (!empty($qty)) { // if the product sku is already in the cart, do this // foreach ($_SESSION['CART']['ITEMS'] as $cart_item => $item) { if ($item['item_sku'] == $sku) { $_SESSION['CART']['ITEMS'][$cart_item]['item_qty'] = $_SESSION['CART']['ITEMS'][$cart_item]['item_qty'] + $qty; $found = true; break; } } // if the product sku is not already in the cart, do this // if (!$found) { $_SESSION['CART']['ITEMS'][] = array('item_sku' => $sku, 'item_qty' => $qty); } } } Link to comment https://forums.phpfreaks.com/topic/205888-looping-over-an-array-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.