Page 1 of 1

An array that needs to be sorted numerically

Posted: Mon Apr 09, 2012 1:25 pm
by lovelf
Hi, I have an array that would like to sort numerically but it also contains strings, when sorted the following comes:

Code: Select all

9{},8{},7{},6{},5{},4{},3{},2{},1{},10{},11{}0{}
When it should be

Code: Select all

11{},10{},9{},8{},7{},6{},5{},4{},3{},2{},1{},0{}
The strings are mandatory for me on this array, it just starts with the right number to be sorted but the sort turns out to be bad, thanks. I'm using rsort($arri);

Re: An array that needs to be sorted numerically

Posted: Mon Apr 09, 2012 1:41 pm
by tr0gd0rr
you will probably need to use usort(), and perhaps strnatcasecmp() will work. If not, you'll need to do some regexes in your usort() callback.