我有这样的阵列从Laravel对象合并征收,这样的访问,$collection->values()->all()
,它返回如下:Laravel - 如何通过不同键的时间戳值对数组对象进行排序?
[
{
"id": "1",
"type": "Teacher",
"created_at": "2017-05-11 18:00:00"
},
{
"id": "2",
"type": "Student"
"created_at": "2017-05-11 15:00:00"
},
{
"id": "3",
"type": "Course",
"data": {
"title: "PHP",
"created_at": "2017-05-11 16:00:00"
}
}
]
我想排序的created_at
领域的秩序,所以它看起来是这样的:
[
{
"id": "1",
"type": "Teacher",
"created_at": "2017-05-11 18:00:00"
},
{
"id": "3",
"type": "Course",
"data": {
"title: "PHP",
"created_at": "2017-05-11 16:00:00"
}
},
{
"id": "2",
"type": "Student"
"created_at": "2017-05-11 15:00:00"
}
]
问题是created_at
是在两个地方,有时是created_at
下和其他时候,它data.created_at
下。
什么问题呢? –
@ mimo的答案正是你所需要的 – Sandeesh