这个问题在这里已有答案:
我试图按索引值对数组进行排序,请看一下给定的数组:
Array
(
[0] => stdClass Object
(
[id] => 645
[fullname] => sumeena
[quoteemail] => [email protected]
[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] => [email protected]
[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] => [email protected]
[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] => [email protected]
[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'对这个数组进行排序,怎么可能呢?
你可以简单地像使用usort
一样
usort($your_array, function($a, $b) {
return strtotime($a->CREATED_ON) - strtotime($b->CREATED_ON);
});
尝试使用:
usort($myArray, function($a, $b) {
return strtotime($a->CREATED_ON) - strtotime($b->CREATED_ON);
});