Order by text and then by number

Posted by Chaim Chaikin on Stack Overflow See other posts from Stack Overflow or by Chaim Chaikin
Published on 2010-06-06T13:36:45Z Indexed on 2010/06/06 13:42 UTC
Read the original article Hit count: 467

Filed under:
|
|
|

I have data like:

Audio 1
File 10
Audio 2
Audio 3
File 11
Audio 13
Audio 22
File 20
Test 22
Audio 10
File 1
File 2

I need it order first by the text (i.e. Audio, File, Test) and then by number (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 etc.)

The problem is that sorting it returns something like this:

Audio 1
Audio 10
Audio 13
Audio 2
Audio 22
Audio 3
File 1
File 10
File 11
File 2
File 20
Test 22

While the result I want is:

Audio 1
Audio 2
Audio 3
Audio 10
Audio 13
Audio 22
File 1
File 2
File 10
File 11
File 20
Test 22

If they were just numbers (i.e. without the audio, file, test) then I could just sort numerically.

However, how can I sort here first by text and then by number.

© Stack Overflow or respective owner

Related posts about php

Related posts about sorting