Skip to content

Instantly share code, notes, and snippets.

@AhmedSamy
Created April 16, 2014 13:01
Show Gist options
  • Save AhmedSamy/10870928 to your computer and use it in GitHub Desktop.
Save AhmedSamy/10870928 to your computer and use it in GitHub Desktop.
Sorting embeded collection
function getSortedIngredients()
{
//workaround to sort ingredients by quantities collection
$iterator = $this->ingredients->getIterator();
$iterator->uasort(
function ($a, $b) {
return ($a->getQuantity() > $b->getQuantity()) ? -1 : 1;
}
);
$ingredients = new ArrayCollection(iterator_to_array($iterator));
$this->ingredients = $ingredients;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment