9th May 2018
9th May 2018
9th June 2018
9th August 2018
8th May 2018
7th June 2018
7th June 2018
如何按升序对这些日期进行排序,并且这些日期位于关联数组中。
答案 0 :(得分:-1)
使用usort可以定义任何自定义排序顺序,在这种情况下,将字符串转换为时间并进行比较:
$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);