开发者

PHP problem sorting values

开发者 https://www.devze.com 2023-03-29 23:31 出处:网络
I have an API returning a kind of date formatted as follow: 2010_m1 for Jan 2010 2010_m2 for Feb 2010 ...

I have an API returning a kind of date formatted as follow: 2010_m1 for Jan 2010 2010_m2 for Feb 2010 ... 2010_m12 for Dec 2010

I have all the dates in an array, and if I use the metho开发者_Go百科d sort, it will sort it like: 2010_m1, 2010_m10, 2010_m11, 2010_m12, 2010_m2, 2010_m3, ...

How could I sort it the 'correct way', ie: 2010_m1, 2010_m2, 2010_m3, ... , 2010_m10, 2010_m11, 2010_m12

Thank you


It's called natural sorting: natsort() is the PHP function for it.

0

精彩评论

暂无评论...
验证码 换一张
取 消