Matt Palermo wrote:
I'm try to sort a list of items using a usort function. Basically, I want
it to sort in this order:
Numbers (0-9)
Letters (Aa-Zz)
Other (anything else)
To explain a little further, I want anything that starts with a number to
show up first in the sorted list, then anything that starts with a letter,
and finally anything that starts with some other character. My usort
function I'm using now gives me results close to this, but it sorts it as
follows (which is wrong for what I need):
Numbers (0-9)
Other (anything else)
Letters (Aa-Zz)
They are all sorted properly alphabetically, but not in the group order that
I need them in. Here is the usort function I'm using right now:
function myUsort($x, $y)
{
if(strtolower($x) == strtolower($y)) return 0;
if(strtolower($x) < strtolower($y)) return -1;
return 1;
}
As I stated above, this provides me with the proper alphabetical results,
but I need it tweaked. Basically this function will give a sorted list like
this:
007
90210
__underscore
abra-cadabra
Zebra
But I need the function to provide a sorted list like this:
007
90210
abra-cadabra
Zebra
__underscore
Anyone know what I need to do to get these results? Please let me know.
Thanks,
Matt Palermo
http://sweetphp.com
Did you try natcasesort()? Seems like I recall, it's pretty close to what you need.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php