fork download
  1. <?php
  2.  
  3. $data = array(
  4. array("date" => "2018-01-21", "count" => 1, "peopleCount"=> 2),
  5. array("date" => "2018-01-22", "count" => 1, "peopleCount"=> 3),
  6. array("date" => "2018-01-19", "count" => 1, "peopleCount"=> 4),
  7. array("date" => "2018-01-25", "count" => 1, "peopleCount"=> 5)
  8. );
  9.  
  10.  
  11. usort($data, function($d1, $d2){
  12. $t1 = strtotime($d1['date']);
  13. $t2 = strtotime($d2['date']);
  14. if ($t1 === $t2) return 0;
  15. return ($t1 > $t2) ? -1 : 1;
  16. });
  17.  
  18. var_dump($data);
Success #stdin #stdout 0.05s 23592KB
stdin
Standard input is empty
stdout
array(4) {
  [0]=>
  array(3) {
    ["date"]=>
    string(10) "2018-01-25"
    ["count"]=>
    int(1)
    ["peopleCount"]=>
    int(5)
  }
  [1]=>
  array(3) {
    ["date"]=>
    string(10) "2018-01-22"
    ["count"]=>
    int(1)
    ["peopleCount"]=>
    int(3)
  }
  [2]=>
  array(3) {
    ["date"]=>
    string(10) "2018-01-21"
    ["count"]=>
    int(1)
    ["peopleCount"]=>
    int(2)
  }
  [3]=>
  array(3) {
    ["date"]=>
    string(10) "2018-01-19"
    ["count"]=>
    int(1)
    ["peopleCount"]=>
    int(4)
  }
}