Reputation: 3601
I've created a shopping cart where the products are stored in cookies, and I display all the cookies using this loop:
foreach($_COOKIE['products'] as $productId => $productQuantity) {
The problem is, every time add 1 to the quantity (so when I change the cookie value), that cookie ends up last in the list of the cart's products. How can I sort these cookies alphabetically, so the order will always be the same?
Many thanks!
Upvotes: 0
Views: 276
Reputation: 17014
Take a look at ksort
.
It will do that, what you want.
This is a Community wiki, since this is solved, and still not shown as this. Feel free to contribute.
Upvotes: 1