2015-10-30 112 views
-1

我有一個數組如何根據數組中的日期進行排序?

Array 
(
    [0] => stdClass Object 
     (
      [id] => 120 
      [project_id] => 143 
      [list_id] => 196 
      [task_id] => 620 
      [message] => New task created byTester by Rohit Garg 
      [date] => 2015-10-30 13:10:54 
      [user_id] => 1 
     ) 

    [1] => stdClass Object 
     (
      [id] => 121 
      [project_id] => 143 
      [list_id] => 0 
      [task_id] => 620 
      [message] => Task Completed Tester by Rajat Jain 1 
      [date] => 2015-10-30 13:10:18 
      [user_id] => 49 
     ) 

    [2] => stdClass Object 
     (
      [id] => 110 
      [project_id] => 143 
      [list_id] => 196 
      [task_id] => 616 
      [message] => New task created bysadasd by saurabh 
      [date] => 2015-10-30 12:10:46 
      [user_id] => 55 
     ) 

    [3] => stdClass Object 
     (
      [id] => 109 
      [project_id] => 143 
      [list_id] => 196 
      [task_id] => 0 
      [message] => New task list created byadsadasd by saurabh 
      [date] => 2015-10-30 12:10:30 
      [user_id] => 55 
     ) 

    [4] => stdClass Object 
     (
      [id] => 108 
      [project_id] => 143 
      [list_id] => 0 
      [task_id] => 0 
      [message] => New Project created sdad by saurabh 
      [date] => 2015-10-30 12:10:21 
      [user_id] => 55 
     ) 

    [5] => stdClass Object 
     (
      [id] => 114 
      [project_id] => 143 
      [list_id] => 196 
      [task_id] => 618 
      [message] => New task created bydsf by saurabh 
      [date] => 2015-10-30 12:10:20 
      [user_id] => 55 
     ) 

    [6] => stdClass Object 
     (
      [id] => 111 
      [project_id] => 143 
      [list_id] => 196 
      [task_id] => 617 
      [message] => New task created byasdasd by saurabh 
      [date] => 2015-10-30 12:10:16 
      [user_id] => 55 
     ) 

    [7] => stdClass Object 
     (
      [id] => 107 
      [project_id] => 142 
      [list_id] => 0 
      [task_id] => 0 
      [message] => New Project created sdad by Rohit Garg 
      [date] => 2015-10-30 11:10:34 
      [user_id] => 1 
     ) 

    [8] => stdClass Object 
     (
      [id] => 106 
      [project_id] => 141 
      [list_id] => 195 
      [task_id] => 615 
      [message] => New task created bysdasd by Rohit Garg 
      [date] => 2015-10-30 10:10:37 
      [user_id] => 1 
     ) 

    [9] => stdClass Object 
     (
      [id] => 104 
      [project_id] => 141 
      [list_id] => 195 
      [task_id] => 614 
      [message] => New task created bysdsad by Rohit Garg 
      [date] => 2015-10-30 10:10:34 
      [user_id] => 1 
     ) 

    [10] => stdClass Object 
     (
      [id] => 103 
      [project_id] => 141 
      [list_id] => 195 
      [task_id] => 0 
      [message] => New task list created bydasd by Rohit Garg 
      [date] => 2015-10-30 10:10:16 
      [user_id] => 1 
     ) 

    [11] => stdClass Object 
     (
      [id] => 99 
      [project_id] => 140 
      [list_id] => 194 
      [task_id] => 612 
      [message] => New task created bysdasd by saurabh 
      [date] => 2015-10-30 10:10:59 
      [user_id] => 55 
     ) 

    [12] => stdClass Object 
     (
      [id] => 96 
      [project_id] => 140 
      [list_id] => 194 
      [task_id] => 0 
      [message] => New task list created by3213123213 by saurabh 
      [date] => 2015-10-30 10:10:49 
      [user_id] => 55 
     ) 

    [13] => stdClass Object 
     (
      [id] => 100 
      [project_id] => 140 
      [list_id] => 194 
      [task_id] => 613 
      [message] => New task created bydsfsdf by saurabh 
      [date] => 2015-10-30 10:10:34 
      [user_id] => 55 
     ) 

    [14] => stdClass Object 
     (
      [id] => 97 
      [project_id] => 140 
      [list_id] => 194 
      [task_id] => 611 
      [message] => New task created bysas by saurabh 
      [date] => 2015-10-30 10:10:08 
      [user_id] => 55 
     ) 

    [15] => stdClass Object 
     (
      [id] => 122 
      [project_id] => 145 
      [list_id] => 0 
      [task_id] => 0 
      [message] => New Project created dfsf by saurabh 
      [date] => 2015-10-30 14:10:23 
      [user_id] => 55 
     ) 

    [16] => stdClass Object 
     (
      [id] => 123 
      [project_id] => 145 
      [list_id] => 199 
      [task_id] => 0 
      [message] => New task list created bydasd by saurabh 
      [date] => 2015-10-30 14:10:23 
      [user_id] => 55 
     ) 

    [17] => stdClass Object 
     (
      [id] => 124 
      [project_id] => 145 
      [list_id] => 199 
      [task_id] => 621 
      [message] => New task created fsdf by saurabh 
      [date] => 2015-10-30 14:10:00 
      [user_id] => 55 
     ) 

    [18] => stdClass Object 
     (
      [id] => 93 
      [project_id] => 139 
      [list_id] => 193 
      [task_id] => 0 
      [message] => New task list created bydasdasd by Rohit Garg 
      [date] => 2015-10-30 10:10:48 
      [user_id] => 1 
     ) 

    [19] => stdClass Object 
     (
      [id] => 92 
      [project_id] => 139 
      [list_id] => 192 
      [task_id] => 0 
      [message] => New task list created bydasdasd by Rohit Garg 
      [date] => 2015-10-30 10:10:35 
      [user_id] => 1 
     ) 

    [20] => stdClass Object 
     (
      [id] => 91 
      [project_id] => 139 
      [list_id] => 191 
      [task_id] => 0 
      [message] => New task list created bydasdasd by Rohit Garg 
      [date] => 2015-10-30 10:10:34 
      [user_id] => 1 
     ) 

    [21] => stdClass Object 
     (
      [id] => 94 
      [project_id] => 139 
      [list_id] => 193 
      [task_id] => 610 
      [message] => New task created bydsad by Rohit Garg 
      [date] => 2015-10-30 10:10:09 
      [user_id] => 1 
     ) 

) 

我想根據日期降序排序。簡單的解決方案?

回答

1

您可以使用usort() & strtotime() -

usort($your_array, function($a, $b) { 
    return strtotime($b->date) - strtotime($a->date); 
}); 
+0

爲我工作的感謝 – Ricky

相關問題