PHP按日期排序多维数组

use*_*954 5 php arrays sorting date

我遇到了问题.我有一个多维数组,看起来像这样:

Array ( [0] => 
              Array ( 
                    [0] => Testguy2's post. 
                    [1] => testguy2 
                    [2] => 2013-04-03 
              ) 

        [1] => Array ( 
                    [0] => Testguy's post. 
                    [1] => testguy 
                    [2] => 2013-04-07 
              ) 
);
Run Code Online (Sandbox Code Playgroud)

我想对从最新日期到最早日期的帖子进行排序,所以它看起来像这样:

Array ( [1] => Array ( 
                     [0] => Testguy's post. 
                     [1] => testguy 
                     [2] => 2013-04-07 
               ) 
        [0] => Array ( 
                     [0] => Testguy2's post. 
                     [1] => testguy2 
                     [2] => 2013-04-03
               ) 
);
Run Code Online (Sandbox Code Playgroud)

我该如何排序?

472*_*084 5

function cmp($a, $b){

    $a = strtotime($a[2]);
    $b = strtotime($b[2]);

    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}

usort($array, "cmp");
Run Code Online (Sandbox Code Playgroud)

或者 >= PHP 7

usort($array, function($a, $b){
    return strtotime($a[2]) <=> strtotime($b[2]);
});
Run Code Online (Sandbox Code Playgroud)