I have a shopping cart system in Cakephp, this table has all your usual maguffins: user_ids, product_ids, option_lists ect. It also has quantity.
I currently have some awful nested loops to check if the record is the same as any in there, if so add one to the quantity. If not add a new cart item.
This loop has to check associated list items and product options, so it goes quite deep.
What I'm wondering is if there is a more 开发者_如何学编程elegant way of checking to see if two cart items in a database are similar (everything except for quantity).
Cheers!
Sounds like something that the Set
utility might be able to help with. I've never used it for this purpose, but perhaps Set::isEqual()
or Set::diff()
would get you where you want to be.
精彩评论