排序JSON数据基于UTC时间戳在php从客户端


Sort JSON data based on UTC timestamp in php from client side

我有一个JSON与一些数据。其中一个字段是时间戳。是否有任何方法可以根据时间戳对数据进行排序?请不要向我推荐任何像datatable这样的jQuery插件。我也不想按排序顺序从数据库中获取数据。我使用以下SQL命令:

select * from tablename;

我不想通过使用这样的命令从数据库中获得排序形式的数据。

select * from tablename ORDER BY.....

是否有可能排序JSON数据像我所说的使用PHP??我希望数据根据时间戳按降序排序。有什么建议吗? ?

下面是一个示例数据

http://codepad.viper - 7. - com/tylowv

I tried this…

function sortByYear($a, $b) {
    $dA = new DateTime($a['date']);
    $dB = new DateTime($b['date']);
    return $dA->format('y') - $dB->format('y');
}

$d = json_decode($sample_data, true);
$info = $d['date'];
usort($info, 'sortByYear');
print_r($info);

尝试使用PHP中的array_multisort函数

$date = array();
$d = json_decode($sample_data, true);
foreach ($d as $key => $row)
{
    $date[$key] = $row['date'];
}
array_multisort($date, SORT_DESC, $d);