fork download
  1. <?php
  2. $data = '{"info":[{"id":1, "title":"original title", "name":"john doe", "timestamp":"0.5"}, {"id":2, "title":"another title", "name":"foo bar", "timestamp":"1"}]}';
  3.  
  4. $info = json_decode($data, true)['info'];
  5.  
  6. usort($info, function ($a, $b) {
  7. if ($a['timestamp'] == $b['timestamp']) {
  8. return 0;
  9. }
  10. return ($a['timestamp'] > $b['timestamp']) ? -1 : 1;
  11. });
  12.  
  13. foreach ($info as $item) {
  14. echo "{$item['id']} {$item['title']}\n";
  15. }
Success #stdin #stdout 0.02s 25864KB
stdin
Standard input is empty
stdout
2 another title
1 original title