0

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!

2

1 Answer 1

1

You are looking for natsort (Sort an array using a "natural order" algorithm)

Sign up to request clarification or add additional context in comments.

2 Comments

This is pretty much a link only answer at the moment. Care to flesh it out a little more than this?
I updated my answer with the solution, its just a one liner though :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.