Jump to content

sort problem


ted_chou12

Recommended Posts

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?
Thanks
Ted
Link to comment
https://forums.phpfreaks.com/topic/34547-sort-problem/
Share on other sites

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 );

OR

natsort ( $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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.