9th May 2018
9th May 2018
9th June 2018
9th August 2018
8th May 2018
7th June 2018
7th June 2018
How to sort these dates in ascending order and these dates are in a associative array.
9th May 2018
9th May 2018
9th June 2018
9th August 2018
8th May 2018
7th June 2018
7th June 2018
How to sort these dates in ascending order and these dates are in a associative array.
Using usort you can define any custom sort order, in this case converting the strings into times and comparing them:
$array = array("1" => "9th May 2018",
"2" => "9th May 2018",
"3" => "9th June 2018",
"4" => "9th August 2018",
"5" => "8th May 2018",
"6" => "7th June 2018",
"7" => "7th June 2018",
);
usort($array, function ($a, $b) {
return strtotime($a) > strtotime($b);
});
var_dump($array);