i trying create add cart functionality. using php array_merge
function merge values cart. rows duplicating in array. need solve issue.
if(isset($_session["cart_item"])) { if(is_array($_session["cart_item"])){ if(array_key_exists($productbycode[0]["code"],$_session["cart_item"])) { foreach($_session["cart_item"] $k => $v) { if($productbycode[0]["code"] == $_session["cart_item"][$k]['code']){ $_session["cart_item"][$k]["quantity"] = $_session["cart_item"][$k]["quantity"] + $_post["quantity"]; break; } } } elseif(!array_key_exists($productbycode[0]["code"],$_session["cart_item"]) && !in_array($productbycode[0]["name"], $_session["cart_item"])) { $_session["cart_item"] = array_merge($_session["cart_item"],$itemarray); } } }elseif(!isset($_session["cart_item"])){ $_session["cart_item"] = $itemarray; }
Comments
Post a Comment