Best way to sort an array of data in PHP -


so have following data array:

array (size=10)   0 => int 5   1 => string '5b1' (length=7)   2 => int 4   3 => string '4b1' (length=7)   4 => int 3   5 => string '3b1' (length=7)   6 => int 2   7 => string '2b1' (length=7)   8 => int 1   9 => string '1b1' (length=7) 

what want sort this:

array (size=10)   0 => string 5b1   1 => int '5' (length=7)   2 => string 4b1   3 => int '4' (length=7)   4 => string 3b1   5 => int '3' (length=7)   6 => string 2b1   7 => int '2' (length=7)   8 => string 1b1   9 => int '1' (length=7) 

the hierarchy of numbers never change although there additional level seen here:

7 -> 6b2 -> 6b1 -> 6 -> 5b2 -> 5b1 -> 5 4b2 -> 4b1 -> 4 -> 3b2 -> 3b1 -> 3 -> 2b2 -> 2b1 -> 2 -> 1b2 -> 1b1 -> 1 -> b2 -> b1 

i wondering best way sort in php?

on 1 hand thinking of looping through static hierarchy array top bottom , using order dynamic array.

any other suggestions?

the answer quite simple, mark baker put me on right track.

i used convoluted mix between rsort, krsort , array_flip working solution.

using rsort sort_natural flag did trick.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -