ted_chou12 Posted January 17, 2007 Share Posted January 17, 2007 I see that both sort and rsort both have some problem in ordering uppercase and lowercase, from what i see, they put lowercase first, and then comes the uppercase, despite the lowercase alphabet comes after the uppercase alphabet, why is that so, and can anyone suggest me how i can solve this?ThanksTed Link to comment https://forums.phpfreaks.com/topic/34547-sort-problem/ Share on other sites More sharing options...
utexas_pjm Posted January 17, 2007 Share Posted January 17, 2007 Use natcasesort() (http://www.php.net/manual/en/function.natcasesort.php) this will sort strings lexographrically. The reason sort() sorts strings somewhat counter intuitively is that upper case chars have lower ascii values than lower case chars.Best,Patrick Link to comment https://forums.phpfreaks.com/topic/34547-sort-problem/#findComment-162747 Share on other sites More sharing options...
printf Posted January 17, 2007 Share Posted January 17, 2007 Normal sorting, sort ( $array) is UPPERCASE first. If you need [b]natural[/b] sorting, where as the sort is compared in lower case, that means UPPER CASE characters are compared as lower case characters (insensitive to case), then use...[code]natcasesort ( $array );ORnatsort ( $array );// reset the keys after sorting$array = array_values ( $array );// to reverse the sort and reset the keys, change [b]false[/b] to [b]true[/b], to preserve the keys when reversing!$array = array_reverse ( $array, false );[/code]printf Link to comment https://forums.phpfreaks.com/topic/34547-sort-problem/#findComment-162749 Share on other sites More sharing options...
ted_chou12 Posted January 17, 2007 Author Share Posted January 17, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/34547-sort-problem/#findComment-162875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.