-1
Array
(
    [0] => Array
        (
            [userId] => 907
            [process] => expert
            [date] => 2019-10-01 17:55:09
        )

    [1] => Array
        (
            [userId] => 906
            [process] => undefine
            [date] => 2019-10-01 17:55:23
        )

    [2] => Array
        (
            [userId] => 907
            [process] => comment_or_sendconfirmation
            [date] => 2019-10-01 17:55:35
        )

    [3] => Array
        (
            [userId] => 907
            [process] => expert
            [date] => 2019-10-01 17:55:54
        )

    [4] => Array
        (
            [userId] => 906
            [process] => newcountry
            [species] => 3
            [date] => 2019-10-01 17:56:21
        )

    [5] => Array
        (
            [userId] => 906
            [process] => comment_or_sendconfirmation
            [date] => 2019-10-01 18:06:35
        )
]

I have an array and i want to reorder base on [date] descending sort DESC Closest date must be first alement of array.

I tried something but confused. I am waiting your assists! Thank you

  • How to compare date: https://stackoverflow.com/questions/8722806/how-to-compare-two-dates-in-php – catcon Oct 02 '19 at 11:42

1 Answers1

0

Use usort().

function OrderbyDate($a, $b)
{
    $t1 = strtotime($a['date']);
    $t2 = strtotime($b['date']);
    return $t1 - $t2;
}    
usort($array, 'OrderbyDate');
Vaibhavi S.
  • 1,083
  • 7
  • 20