Page 1 of 1
Case Insensitive sort
Posted: Tue Apr 06, 2004 4:49 pm
by Chris Corbyn
Hi,
Any way to sort an array without putting DJ above Dead etc. Doble caps seem to always go to the top of the list.
Looked in manual but didn't spot anything, i could have missed it though.
Thanks
Posted: Tue Apr 06, 2004 4:59 pm
by markl999
You could sort them numerically, like
sort($array, SORT_NUMERIC);
Posted: Tue Apr 06, 2004 5:03 pm
by johnperkins21
Posted: Tue Apr 06, 2004 6:01 pm
by Chris Corbyn
SORT_NUMERIC is no good because I need my list returned alphabetically.
strtolower looks good though. The only problem is that I need the results of the sort echoed back onto the page in their original format.
It's filenames in a big list so I want to display only the original way they are written even if the sort function sorts them as if they are lower case.
I'm sure that can't be too difficult to do though.
Thanks mate!
Posted: Tue Apr 06, 2004 6:20 pm
by Chris Corbyn
Nice thanks!
I did it like this ($file is each file in a directory)
Code: Select all
$tonefile = substr($file, 0, -4);
$lowercase = strtolower($file);
$ToneArray[$tonefile] = $lowercase;
asort($ToneArray);
foreach ($ToneArray as $n => $v) {
echo ' '.$n.' <br>';
}
Or something to that effect. I didn't copy and paste it so if there are errors in that code above there's no need to tell me.
Posted: Tue Apr 06, 2004 6:29 pm
by Weirdan
or just:
Code: Select all
usort($ToneArray, create_function( '$a,$b', 'return strcasecmp($a,$b);' ) )