Last active
August 17, 2018 11:42
-
-
Save minedun6/24f4d8b70f491d618e401d1ac5977f20 to your computer and use it in GitHub Desktop.
Did you know you can compare DateTime objects in PHP using the spaceship operator
This file contains hidden or 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 | |
$dates = [ | |
DateTime::createFromFormat('Y-m-d', '2000-02-01'), | |
DateTime::createFromFormat('Y-m-d', '1994-01-30'), | |
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:03:33'), | |
DateTime::createFromFormat('Y-m-d', '2006-07-27'), | |
DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-27 12:04:15'), | |
]; | |
usort($dates, function ($a, $b) { | |
return $a <=> $b; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment