|
No offense taken. But that is exactly it! If you were making a list, would you put 1A infront of 10A, because a human would see 10 as 'ten', not 'one' and 'zero'.
Think aisles of a grocery store, or something.
And for the part about the spaces. Looking at that, if I were to, say, make a list of children in my class (I'm not a teacher, but just pretend), I would put "Apple" before "Apple Orange". Weird last names, but you get the point.
I still insist that if you asked an average person to order the list, they would place 1A before 10A and Apple before Apple Orange. I know this isn't how php sees it, because it moves one character at a time, rather than keeping a running tally until the type changes from numeric to alphabetic.
In the end, my research has brought me to usort($myArray, 'strnatcmp');. That solves the problem. And if you read php.net's description of all the ...nat... function varieties, they explain that it sorts them naturally as a human does. So I'm not completely weird! lol
FYI, usort($myArray, 'strnatcmp'); yields:
1A
1
10A
10
Apple Orange
Apple
Good enough for me! haha I can get over the spaces issue. That's probably all in my head...
Last edited by mtd; 07-12-2005 at 11:08 PM..
|