我通过应用这条线解决了这个问题。
sort($imdarrayGG['newDate']);
加值前的输出
[Mon Jul 6 10:33:23 2020] Array
(
[coursedate] => 2020-07-17
[newDate] => Array
(
[0] => 2020-07-30
[1] => 2020-07-07
[2] => 2020-07-08
[3] => 2020-07-17
)
)
我放行后,输出会变成这样。
[Mon Jul 6 10:35:42 2020] Array
(
[coursedate] => 2020-07-17
[newDate] => Array
(
[0] => 2020-07-07
[1] => 2020-07-08
[2] => 2020-07-17
[3] => 2020-07-30
)
)
已经排序的日期是最晚的日期。
这是我们有对象的地方,然后我们要对所有对象进行排序
例子:-
[status_custom] => Array
(
[0] => stdClass Object
(
[type] => LDL - B2
[date] => 23/10/2014
)
[1] => stdClass Object
(
[type] => LDL - D
[date] => 18/04/2015
)
)
首先我们必须转换。 Refer to this link to convert
然后我们对它们进行排序。 Refer to this link to sort object
我们开始:-
//At here we want to sort according to latest date. But this one involve with the object also.
usort($array_custom_object, function ($a, $b) {
$date1 = $a->date;
$date2 = $b->date;
//Since the income date is formatted like this d/m/Y , we have to change it
$date1 = date_format(date_create_from_format('d/m/Y', $date1), 'Y-m-d');
$date2 = date_format(date_create_from_format('d/m/Y', $date2), 'Y-m-d');
if ($date1 > $date2) {
return -1;
}
if ($date1 == $date2) {
return 0;
}
if ($date1 < $date2) {
return 1;
}
});
$dataFinal->status_custom = $array_custom_object; //Result