// create a new ArrayCollection object $collection = new \Doctrine\Common\Collections\ArrayCollection(); // add some items to the collection $item1 = new MyObject(); $collection->add($item1); $item2 = new MyObject(); $collection->add($item2);
// create a new ArrayCollection object $collection = new \Doctrine\Common\Collections\ArrayCollection(); // add multiple items to the collection $items = [new MyObject(), new MyObject(), new MyObject()]; $collection->addAll($items);In this example, we create a new ArrayCollection object and use the "addAll" method to add multiple items to the collection at once. Overall, Doctrine\Common\Collections\ArrayCollection is a useful class for handling collections of objects in PHP applications.