Last active
April 17, 2019 19:44
-
-
Save stefpe/831a1a5492a9f357d7372306fa6ae770 to your computer and use it in GitHub Desktop.
DateTime comparison with spaceship operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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