array_count_values ​​sonra dizi sıralama

5 Cevap php

Ben ürünleri bir dizi var

$products = array_count_values($products);

now I have an array where $key is product number and $value is how many times I have such a product in the array. I want to sort this new array that product with the least "duplicates" are on the first place, but what ever I use (rsort, krsort,..) i loose product numbers (key).

herhangi bir öneriniz?

teşekkürler.

5 Cevap

Just a thought; asort - sorts ascending (low to high)

belki de deneyin

dsort - (yüksekten düşüğe) azalan