PHP - sorting an array of filenames with numbers?

前端 未结 2 1563
南笙
南笙 2020-12-11 04:10

Can anyone tell me how to sort an array containing filenames that start with numbers? Because strings that start with 11, 12, 13 etc are considered lower than 2, it\'s scewi

相关标签:
2条回答
  • 2020-12-11 04:23

    Use can get the natural ordering using natsort

    See it.

    0 讨论(0)
  • 2020-12-11 04:31

    You can use natsort. or natcasesort, which is case insensitive. If there is more than numbers (ie. diacritics), you should assure that you use proper locale.

    If it is not enough, ie. you want also sort number literals ("one", "two", "three"), you can use usort, which permits to use your custom callback as comparison function.

    0 讨论(0)
提交回复
热议问题