I solved this problem by applying this line.
sort($imdarrayGG['newDate']);
Output before adding the value
[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
)
)
After I put the line, the output will become like this.
[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
)
)
The date already sorted which is the latest date will be at the up.
This is where we have object and then we want to sort all of them
Example:-
[status_custom] => Array
(
[0] => stdClass Object
(
[type] => LDL - B2
[date] => 23/10/2014
)
[1] => stdClass Object
(
[type] => LDL - D
[date] => 18/04/2015
)
)
First we have to convert. Refer to this link to convert
And then we sort them. Refer to this link to sort object
Here we go:-
//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