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
Setutility might be able to help with. I’ve never used it for this purpose, but perhapsSet::isEqual()orSet::diff()would get you where you want to be.