Order alphanumerical list in PHP
HI, i need to order a list in PHP that looks like: B1200 120A81 00A12 00A22 C100B C100C
ordered list would be: 00A12 00A22 120A81 B1200 C100B C100C
I was thinking about splittin开发者_C百科g each line in multidimensional arrays and order it but i am stuck and maybe theres a completely different way for that.
Thanks!
If the normal sort function will do what you want then splitting/sorting it would be easy:
// break up the string into an array on spaces
$new_array = explode(' ', $input);
// sort the array
sort($new_array);
// put the string back together
$sorted_string = implode(' ', $new_array);
or, more succinctly:
$sorted_string = implode(' ', sort(explode(' ', $input)));
If the default sort()
won't give you what you want you should check out the usort() function.
精彩评论