Page 1 of 1

Sort 2D array by date

Posted: Fri Dec 18, 2009 3:11 am
by 4dplane
Hi, I have some code that sorts an array of dates that I first convert into YYYYDDMM format with sort($ISOSDates, SORT_NUMERIC). What I need to do is add a piece of data to each to each date array that is being sorted before it's sorted. So if I have an array sortedDateData that has dates added to it like this:

sortedDateData[$i] = array($year$monthNum$dayNum, $mediaId).

how can I sort the array by $year$monthNum$dayNum?

So the new sortedDateData[0][0] would have the first date
then sortedDateData[1][0] would have the next date

thanks,
4dplane

Re: Sort 2D array by date

Posted: Fri Dec 18, 2009 3:33 am
by papa
array_multisort

Should work.

Re: Sort 2D array by date

Posted: Fri Dec 18, 2009 9:39 am
by AbraCadaver
I don't think you're going to get a proper sort using YYYYDDMM, but it depends upon what you want.

Re: Sort 2D array by date

Posted: Fri Dec 18, 2009 1:28 pm
by daedalus__
why dont you convert them to unix timestamps then sort them as you add them to your list?