如何按索引值重新排序数组?

时间:2015-10-08 07:03:41

标签: php arrays

我正在尝试按索引值对数组进行排序,请查看给定的数组:

Array
(
    [0] => stdClass Object
        (
            [id] => 645
            [fullname] => sumeena
            [quoteemail] => sumeena@creatinemarketing.com
            [budget] => $2000+
            [user_id] => 681
            [p_notif_by] => 1,36,31,41,39,38,37,32
            [created_on] => 2015-10-07 06:55:05
            [CREATED_ON] => 2015-10-07 06:54:35
        )

    [1] => stdClass Object
        (
            [id] => 641
            [fullname] => sumeena
            [quoteemail] => sumeena@ourdesignz.com
            [budget] => $2000+
            [user_id] => 677
            [p_notif_by] => 1,36,31,41,39,38,37,32
            [created_on] => 2015-10-07 03:14:41
            [CREATED_ON] => 2015-10-07 03:13:13
        )

    [2] => stdClass Object
        (
            [id] => 640
            [fullname] => Test Do Not Delete
            [quoteemail] => kamaldipkaur6785@gmail.com
            [budget] => $1,500-$2,000
            [user_id] => 676
            [p_notif_by] => 1,39,36,31,41,38,37,32
            [created_on] => 2015-10-07 02:43:16
            [CREATED_ON] => 2015-10-07 02:43:16
        )

    [3] => stdClass Object
        (
            [id] => 19
            [fullname] => Chris Tou Is Testing
            [quoteemail] => fobtastic@outlook.com
            [budget] => More than $2,000
            [user_id] => 47
            [p_notif_by] => 32,36,38,1,31,34,41,37,42,35,45,39,40,44,92,252,596,640,648,646
            [created_on] => 2015-09-07 23:49:35
            [CREATED_ON] => 2015-09-08 12:29:03
        )

)

所以,这是数组,现在我想用索引'CREATED_ON'对这个数组进行排序,怎么可能呢?

2 个答案:

答案 0 :(得分:3)

尝试使用:

usort($myArray, function($a, $b) {
    return strtotime($a->CREATED_ON) - strtotime($b->CREATED_ON);
});

答案 1 :(得分:2)

您可以像{/ p>一样使用usort

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