Laravel按日期对集合进行排序
问题描述:
我有这个收集结果:
$result = [{
"date": "2016-03-21",
"total_earned": "101214.00"
},
{
"date": "2016-03-22",
"total_earned": "94334.00"
},
{
"date": "2016-03-23",
"total_earned": "96422.00"
},
{
"date": "2016-02-23",
"total_earned": 0
},
{
"date": "2016-02-24",
"total_earned": 0
},
{
"date": "2016-02-25",
"total_earned": 0
}]
我想按日期对结果进行排序:
I want to sort the result by date:
$sorted = $transaction->sortBy('date')->values()->all();
但是我没有得到预期的结果:
But I don't get the expected result:
[{
"date": "2016-02-23",
"total_earned": 0
},
{
"date": "2016-02-24",
"total_earned": 0
},
{
"date": "2016-02-25",
"total_earned": 0
},
{
"date": "2016-03-22",
"total_earned": "94334.00"
},
{
"date": "2016-03-21",
"total_earned": "101214.00"
},
{
"date": "2016-03-23",
"total_earned": "96422.00"
}]
如您所见,第2个月的所有内容均已正确排序.但是在第3个月开始混乱了. (实际结果比这更长,并且从第3个月开始混乱)
As you can see all with month 2 is sort properly. However at month 3 it start messed up. (the real result is longer than this and it messed up start at month 3)
有什么方法可以使其正确排序吗?
Any solution to make it sort properly?
谢谢.