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? Link to comment https://forums.phpfreaks.com/topic/187563-uksort-help/ 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? Link to comment https://forums.phpfreaks.com/topic/187563-uksort-help/#findComment-990282 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 ) Link to comment https://forums.phpfreaks.com/topic/187563-uksort-help/#findComment-990286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.