Page 1 of 1

A sorting question

Posted: Fri Nov 26, 2010 2:16 pm
by nate_24
Hey,

I am trying to sort an array sorting by numbers first and letters second.

For example: an array could look like $array = ('1', 'C9', 'E2', '2', 'C11', ... etc.);

I would like it to output in the order: 1, 2, C9, C11, E2. But right now the code I have outputs: C9, C11, E2, 1, 2. Any help is appreciated. Thanks!

Re: A sorting question

Posted: Fri Nov 26, 2010 2:43 pm
by McInfo
Try natsort() or natcasesort().

It that isn't suitable, write your own comparison function and use usort().

Re: A sorting question

Posted: Fri Nov 26, 2010 3:17 pm
by nate_24
natsort() worked. Thank you for the suggestion.