简体   繁体   English

PHP:按字母顺序对cookie进行排序?

[英]PHP: Sort cookies alphabetically?

I've created a shopping cart where the products are stored in cookies, and I display all the cookies using this loop: 我创建了一个购物车,其中产品存储在cookie中,并使用以下循环显示所有cookie:

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. 问题是,每次向数量添加1(因此,当我更改cookie值时),该cookie最终出现在购物车产品列表中。 How can I sort these cookies alphabetically, so the order will always be the same? 我如何按字母顺序对这些cookie进行排序,所以顺序将始终相同?

Many thanks! 非常感谢!

Take a look at ksort . 看一下ksort

It will do that, what you want. 它将执行您想要的操作。


This is a Community wiki, since this is solved, and still not shown as this. 这是一个社区Wiki,因为已解决此问题,但仍未显示为此。 Feel free to contribute. 随时贡献。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM