Page 1 of 1

array sorting

Posted: Thu Oct 20, 2005 4:34 pm
by s.dot
original array:

Code: Select all

$array = array(B => 1, X => 3, A =>1, F => 3);
I run asort() on this and get the following result

Code: Select all

Array (
   [B] => 1
   [A] => 1
   [X] => 3
   [F] => 3
)
So that's cool. But now, when two or more keys have the same value, I'd like to sort those keys in alphabetical order, so the above array would look like this.

Code: Select all

Array (
   [A] => 1
   [B] => 1
   [F] => 3
   [X] => 3
)
I need to maintain the same order of the numbers, for example 1s first then 3s, but rearrange the keys alphabetically.

I hope I explained that well. =/

Posted: Thu Oct 20, 2005 5:35 pm
by feyd
ksort() and/or multisort() and/or usort()

Posted: Thu Oct 20, 2005 10:18 pm
by s.dot
yeahhh, but when I run any of those on the array they effect the whole thing. I need to sort by value (sort_numeric) , then sort the key alphabetically