我需要从getNotifications功能由值“起始日期” DESC顺序通知数组进行排序:排序PHP数组
$posts_id_arr = getPoststIds($conn);
foreach ($posts_id_arr as $key => $val) {
$total_arr[$key] = [
'notification' => getNotifications($val['post_id'], $user_id, $conn)
];
}
$response_array = array('data' => $total_arr, 'more things' => $more_array);
echo json_encode($response_array);
现在的顺序是按帖子的ID,由于foreach循环。
data {
notification:
[
{
post_id: “1",
start_date: "2016-10-10 08:00:00",
},
{
post_id: “1",
start_date: "2016-10-10 12:00:00",
}
],
notification:
[
post_id: “2",
start_date: "2016-10-10 09:00:00",
},
{
post_id: “2",
start_date: "2016-10-10 13:00:00",
}
]
}
,我需要它是1:08:00,2:09:00,1:12:00,2:13:00
我认为你应该在循环后对数据进行排序,这会有所帮助,并且需要更少的迭代。 –
可能的重复[PHP排序数组的子数组值](http://stackoverflow.com/questions/2477496/php-sort-array-by-subarray-value) – Epodax
@吉拉德阿达尔。你有没有尝试过我的解决方案。如果不尝试和分享想法,如果你遇到任何障碍,让我知道,以便我们纠正它。 –