asmith Posted January 7, 2010 Share Posted January 7, 2010 Hello. I have an array like this and trying to sort it by its keys: <?php $as = array(4 => 'a', 1 => 'd', 'A' => 'f', 10 => 'g'); function natSortMe($a, $b) { if ($b == 'A') return -1; if ($a == $b) return 0; else return $a > $b? -1 : 1; } uksort($as, 'natSortMe'); print_r($as); ?> I want the letter key comes first, then number from highest to lowest. the code above returns this: Array ( [10] => g [4] => a [1] => d [A] => f ) any idea? Quote Link to comment Share on other sites More sharing options...
RaythMistwalker Posted January 7, 2010 Share Posted January 7, 2010 how would it look the way you want it to return? Quote Link to comment Share on other sites More sharing options...
asmith Posted January 7, 2010 Author Share Posted January 7, 2010 Array ( [A] => f [10] => g [4] => a [1] => d ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.