fork(2) download
  1. <?php
  2.  
  3. // your code goes here
  4. $json = '{
  5. "items": [
  6. {
  7. "id": "8498",
  8. "title": "Item 2",
  9. "pubdate": "2015-03-01 10:29:00 +0000"
  10. },
  11. {
  12. "id": "8497",
  13. "title": "Item 1",
  14. "pubdate": "2015-03-01 16:29:00 +0000"
  15. }
  16. ]
  17. }';
  18.  
  19. $arr = json_decode($json, true);
  20.  
  21. $items = $arr['items'];
  22.  
  23. usort($items, function($a, $b) {
  24. if ($a['pubdate'] == $b['pubdate'])
  25. return $a['id'] < $b['id'];
  26.  
  27. return ($a['pubdate'] < $b['pubdate']) ? -1 : 1;
  28. });
  29.  
  30. print_r($items);
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [id] => 8498
            [title] => Item 2
            [pubdate] => 2015-03-01 10:29:00 +0000
        )

    [1] => Array
        (
            [id] => 8497
            [title] => Item 1
            [pubdate] => 2015-03-01 16:29:00 +0000
        )

)