ozzles2006 Posted October 25, 2006 Share Posted October 25, 2006 I'm trying to build an e-commerce type website...I couldn't get a "shopping cart" array to store in a session variable, so I gave up and started on cookies instead. So.. I have a string that I'm getting from a cookie. It's in the format "1,2,1,3,4,5" and so on (no particular order) depending on what's been put into it.I'm just wondering if theres any way to delete, for example, 1 instance of "2," or "5"? I can do it to remove all entries, but I only want it to do it once. Quote Link to comment Share on other sites More sharing options...
ozzles2006 Posted October 25, 2006 Author Share Posted October 25, 2006 Thought I should post the bit of code I'm dealing with.[quote]$cart=$_COOKIE['cart']; $item = $_POST['id']; $qty = $_POST['qty']; if (strlen($cart)==1) { setcookie('cart',''); echo "<meta content='0;url=index.php?p=checkout' http-equiv='refresh' />"; } else { $cart = explode("|", $_COOKIE['cart']); $cart_count = array_count_values($cart); foreach ($cart_count as $itemNum => $qty) { } echo "<meta content='0;url=index.php?p=checkout' http-equiv='refresh' />"; }[/quote]Basically what I'm doing is using the array_count_values method to "group by" the item number.So what I want to do is reduce the quantity for the item corresponding to the button that's been pressed and then regenerate the string and add it to the cookie again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.