PDA

View Full Version : Case Sensitive/REAL Alphabetizing


hofan41
08-13-2002, 06:42 PM
I was just wondering if anyone had the function or knew the code to sorting in php so that it would be sorted according to the alphabet instead of total ASCII value, what I want the function to do is take something like

array ("ABC`xx`123129081094","BDCrrZ`xx`1239885738","123`xx`9289742","AcCDD`xx`9483984323")

and sort it correctly because with total ASCII value, using strings that also contain numbers will not alphabetize things correctly. So if you know how I would go about accomplishing this, please respond. Thanks.

mordred
08-13-2002, 07:01 PM
Do you mean sth. like


usort($array, "strnatcmp");


Though I don't know if that's close to your idea of right alphabetization... mine might differ from yours, as they are language/country specific AFAIK.

hofan41
08-13-2002, 07:06 PM
when I try that, it pumps out the

Wrong datatype in usort() call

error.

Also, what I mean by real alphabetizing is that it compares it by the first letters instead of the whole string value.

So something like AAAC9999999999 would come before BB111 because if it were done in ascii value AAAC99999999 would have a greater value and thus come after BB111.

mordred
08-13-2002, 07:49 PM
$array in my example code has to be an array to work.

hofan41
08-13-2002, 07:50 PM
doh, lol. let me go try that.

hofan41
08-13-2002, 07:52 PM
yes! tried it and it works like a charm. what does that strnatcmp mean anyways?