sorting - Can't sort dates with PHP -
this question has answer here:
- how sort date array in php 4 answers
i have php array looks this:
$dates = array(); $dates['01-07-2013'] = 'dummy data'; $dates['01-21-2013'] = 'dummy data'; $dates['01-28-2013'] = 'dummy data'; $dates['01-20-2012'] = 'dummy data';
when using ksort($dates) it's not sorting them correctly. there way sort keys this?
i expect sort return:
'01-30-2012', '01-07-2013', '01-21-2013', '01-28-2013',
those aren't dates, far php concerned. they're strings, it's applying standard string sorting rules it.
you'll need define custom sort function use usort()
, or convert dates format sortable string, e.g.
yyyy-mm-dd
Comments
Post a Comment