Reputation: 7233
I have those elements in an array:
/mypath/10_something_04_06.txt
/mypath/1_something_04_06.txt
/mypath/12_something_04_06.txt
/mypath/2_something_04_06.txt
/mypath/3_something_04_06.txt
Now I want to sort it, so that the numbers after /mypath/
are considered. This is what I tried:
sort($myArray, SORT_NUMERIC);
sort($myArray, SORT_STRING );
It doesn't work. Should be expected result like below:
/mypath/1_something_04_06.txt
/mypath/2_something_04_06.txt
/mypath/3_something_04_06.txt
/mypath/10_something_04_06.txt
/mypath/12_something_04_06.txt
Thanks!
Upvotes: 0
Views: 42
Reputation: 4020
You are looking for natsort (Sort an array using a "natural order" algorithm)
Upvotes: 1