I need to check if the Email
object already ArrayCollection
in the ArrayCollection
, but I have to check the email as strings (Entity contains an identifier and some relationships with other persons, for this reason I use a separate table that saves all emails).
Now, in the first, I wrote this code:
foreach ($this->emails as $existentEmail) { if ($existentEmail->getEmail()->getEmail() === $email->getEmail()) {
But after reading the ArrayCollection
class, I saw the exists
method, which seems to be a more elgetic way to do the same thing as I did.
But I do not know how to use it: can someone explain to me how to use this method, given the above code?
source share