Skip to content

Instantly share code, notes, and snippets.

@Sergic
Forked from marijn/Example.php
Created July 31, 2013 09:05
Show Gist options
  • 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