Initializes a new ArrayCollection.
public __construct ( array $elements = [] ) | ||
$elements | array |
use Doctrine\Common\Collections\ArrayCollection; // Create a new ArrayCollection object $collection = new ArrayCollection(['apple', 'orange', 'banana']); // Output the collection var_dump($collection);In this example, the __construct method is used to create a new ArrayCollection object called $collection. The array of fruit strings is passed as an argument to the constructor. The var_dump() function is then used to output the contents of the collection. The ArrayCollection class is commonly used in conjunction with the Doctrine ORM and is a useful tool for managing and manipulating collections of objects in PHP.