views:

36

answers:

1

Hi,

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!

+1  A: 

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.

Rob Wilkerson
Yup, just remember to `unset` any keys you are not interested in before comparing.
deizel