Skip to content

Instantly share code, notes, and snippets.

@Sergic
Forked from marijn/Example.php
Created July 31, 2013 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sergic/6120549 to your computer and use it in GitHub Desktop.
Save Sergic/6120549 to your computer and use it in GitHub Desktop.
<?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