Check if ArrayCollection is empty
Doctrine ArrayCollection has a method isEmpty that will do what you are looking for. if ($suppliers->isEmpty()) { } Take a look at the documentation for it here
Doctrine ArrayCollection has a method isEmpty that will do what you are looking for. if ($suppliers->isEmpty()) { } Take a look at the documentation for it here
Doctrine now has Criteria which offers a single API for filtering collections with SQL and in PHP, depending on the context. https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections Update This will achieve the result in the accepted answer, without getting everything from the database. use Doctrine\Common\Collections\Criteria; /** * @ORM\Entity */ class Member { // … public function getCommentsFiltered($ids) { $criteria = … Read more
Better (and working) variant for me: $collection3 = new ArrayCollection( array_merge($collection1->toArray(), $collection2->toArray()) );