Possible Duplicate:
Preserve key order (stable sort) when sorting with PHP’s uasort
I have an array:
$temp = Array('a' => 0, 'b' => 0,'c' => 1,'d' => 1,'e' => 0,'f' => 0,'g' => 2,'h' => 0);
That I want to sort via its values in ascending order:
asort($temp);
print_r($temp);
gives:
Array
(
[e] => 0
[a] => 0
[h] => 0
[b] => 0
[f] => 0
[d] => 1
[c] => 1
[g] => 2
)
But I somehow want to preserve the structure of entries that have the same value, example:
Array
(
[a] => 0
[b] => 0
[e] => 0
[f] => 0
[h] => 0
[c] => 1
[d] => 1
[g] => 2
)
I'm thinking this is less of a "sort" and more of an array function filter/map/walk, but I cant see any efficiently way of making this work.
Bit more info: I need to sort up to 500 values, approx 3500 times, so speed and efficiency is paramount. These numbers will grow on a daily basis, as the process will be running overnight.
Any ideas? Thanks.
EDIT: I need to preserve both key and value, hence the use of asort. I can only order by the value as there will be multiple entries of the same value. The keys in my example of alphabetic to easier explain my query, but in actuality are numeric and will not be in chronological order.