case insensitive sort()
Posted: Wed Jun 14, 2006 5:08 pm
Is there any case-insensitive way to sort arrays? I keep getting this order with sort()
Tyson
Willy
Zoology
luke
mc2
oggy
test
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Tyson
Willy
Zoology
luke
mc2
oggy
test
Code: Select all
function mysort($a, $b) {
return strcmp(strtolower($a), strtolower($b));
}
usort($myarray, "mysort");I have tried both of them and still come up with:feyd wrote:natcasesort(), or shockers of shockers: usort()
Code: Select all
function mysort($a, $b) {
return strcmp(strtolower($a), strtolower($b));
}
usort($directories, "mysort");
/* Both give me this:
This is a folder
Zoology
luke
mc2
test*/Code: Select all
usort($directories, 'strcasecmp');