I have an array of values which are either all-letters or all-numbers and need to sort them in an ascending fashion. Additionally, I want all-numeric values to be moved to the end of the array so that they occur after all of the non-numeric values.
$test = ["def", "yz", "abc", "jkl", "123", "789", "stu"];
If I run sort()
on it I get:
Array
(
[0] => 123
[1] => 789
[2] => abc
[3] => def
[4] => jkl
[5] => stu
[6] => yz
)
but I'd like to see:
Array
(
[0] => abc
[1] => def
[2] => jkl
[3] => stu
[4] => yz
[5] => 123
[6] => 789
)
I tried array_reverse()
, but that didn't seem to change anything. I'm at a loss for how to get the numbers last, but in ascending order.
sort()
but, I guess overall the answers below make sense. Thank you all, I will give them a shot, and come back with which one works best for my need – Shephard