2014-06-11 280 views
0

我有一个数组这些元素:通过包含数字对字符串数组进行排序?

/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 

现在我想对它进行排序,从而使/mypath/后的数字被认为是。这是我试过的:

sort($myArray, SORT_NUMERIC); 
sort($myArray, SORT_STRING); 

它不起作用。 应该会有如下结果:

/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 

谢谢!

+3

查一查'natsort'。 – georg

+0

是的,那是一个,谢谢! – user1856596

+0

[按字母顺序排列php数组]的可能重复(http://stackoverflow.com/questions/8295819/sorting-a-php-array-alphanumerically) – kero

回答

1

您正在寻找natsort(使用排序“自然排序”算法对数组)

+0

这几乎是目前仅有的链接答案。关心它比这更加丰富吗? – Fluffeh

+1

我用解决方案更新了我的答案,尽管它只是一个班轮:)。 – user1856596

相关问题