laravel sort an array by date

后端 未结 4 600
难免孤独
难免孤独 2021-01-06 02:17

hello friends I have an array that looks like this:

array:3 [▼
  0 => array:6 [▼
    \"date\" => \"2016-05-31 15:08:33\"
    0 => \"31 May 16\"
             


        
4条回答
  •  长情又很酷
    2021-01-06 03:05

    You can use usort() with custom comarison function.

    function sortByDate($arr1, $arr2)
    {
        $tmp1 = strtotime($arr1['date']);
        $tmp2 = strtotime($arr2['date']);
        return $tmp1 - $tmp2;
    }
    usort($array, 'date');
    

提交回复
热议问题