symfonydoctrine-ormarraycollection

What are Collections and ArrayCollections in entities?


Can someone use simple words to explain Collections, especially ArrayCollections, in entities to me? What are they? When and how to use them?

(Maybe provide a simple example).


Solution

  • So the ArrayCollection is a simple class that implements Countable, IteratorAggregate, ArrayAccess SPL interfaces, and the interface Selectable made by Benjamin Eberlei.

    Not much information there if you are not familliar with SPL interfaces, but ArrayCollection - permit you to save the object instances in an array like form but in an OOP way. The benefit of using the ArrayCollection, instead of standard array is that this will save you a lot of time and work, when you will need simple methods like count, set, unset iterate to a certain object, and most of all very important:

    When to use it: