unable to sort date using usort

纵然是瞬间 提交于 2019-12-12 17:19:08

问题


I have user defined function sort which sorts by date. It works fine for the same year and does not work when the year changes. This an example of the dates that is sorted by the function:

 01/02/2013  
 01/03/2013 
 12/12/2012  

 function mysort($a,$b) {
   return $a['date']>$b['date'];
 }

 usort($arr,"mysort");

This is an old application which uses php4. Is there a way where I can compare dates directly?


回答1:


Use strtotime.

function mysort($a,$b) {
    return strtotime($a['date'])>strtotime($b['date']);
}


来源:https://stackoverflow.com/questions/14146520/unable-to-sort-date-using-usort

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!