sorting - Can't sort dates with PHP -


this question has answer here:

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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -