Skip to content

Instantly share code, notes, and snippets.

@stefpe
Last active April 17, 2019 19:44
Show Gist options
  • Save stefpe/831a1a5492a9f357d7372306fa6ae770 to your computer and use it in GitHub Desktop.
Save stefpe/831a1a5492a9f357d7372306fa6ae770 to your computer and use it in GitHub Desktop.
DateTime comparison with spaceship operator
<?php
$list = [
new DateTime('yesterday'),
new DateTime('today'),
new DateTime('1 week ago'),
];
usort($list, function ($a, $b) {
return $a <=> $b;
});
var_dump($list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment