I'm looking for the shortest way to retrieve an element from a Doctrine ArrayCollection
by it's Id. Currently I'm doing something like this (which obviously is a bit clunky):
function public getAddressById( $customer, $addressId )
{
$addresses = $customer->getAddresses();
foreach( $addresses as $address )
{
if( $address->getId() == $addressId )
{
return $address;
}
}
return NULL;
}
Is there a shorter way (syntax wise) to retrieve an element by it's Id from a Doctrine ArrayCollection
?