-
-
Save Sergic/6120549 to your computer and use it in GitHub Desktop.
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 | |
$collection = new Doctrine\Common\Collection\ArrayCollection(); | |
// add objects to the collection that contain a getCreated method returning a DateTime instance | |
$iterator = $collection->getIterator(); | |
$iterator->uasort(function ($first, $second) { | |
if ($first === $second) { | |
return 0; | |
} | |
return (float) $first->getCreated()->format("U.u") < (float) $second->getCreated()->format("U.u") ? -1 : 1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment