Question

I have an array that looks like this

array(24) { ["#HiddenId"]=> string(24) "2013-11-08T11:59:54.378Z"] }

It has multiple ids/dates but I want to sort it by date (most recent)

I know how to do this for this format, "01/01/2014" however I Believe it is easier to work with this format, but I'm unsure of how to implement.

This is the code I have for format "01/01/2014"

uasort($fileList, "my_sort");

function my_sort($a,$b)
{
    $date1 = DateTime::createFromFormat('d/m/Y', $a);
    $date2 = DateTime::createFromFormat('d/m/Y', $b);
    return $date1 < $date2;
}

I need to do this function similar but for the other format shown above.

Any help is appreciated

Was it helpful?

Solution

Very simple:

usort($yourArray,"strcmp");

"Big-endian" formats like Y-m-d H:i:s sort lexicographically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top