I have a JSON with some data. One of the fields is a timestamp. Is there any way to sort the data based on the timestamp? Please don't recommend me any jQuery plugins like DataTables. And I don't want to fetch the data from the database in sorted order either. I use the following SQL command.
select * from tablename;
I don't want to get the data in sorted form from database by using a command something like this.
select * from tablename ORDER BY.....
Is it possible to sort JSON data like what I've said using PHP??? I want the data to be sorted in the descending order based on the timestamp. Any suggestions???
Here is a sample data
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);