Throoze Throoze - 1 year ago 157
PHP Question

How to merge two php Doctrine 2 ArrayCollection()

Is there any convenience method that allows me to concatenate two Doctrine

? something like:

$collection1 = new ArrayCollection();
$collection2 = new ArrayCollection();




// $collection1 now contains {$obj1, $obj2, $obj3, $obj4, $obj5, $obj6 }

I just want to know if I can save me iterating over the 2nd collection and adding each element one by one to the 1st collection.


Answer Source

Better (and working) variant for me:

$collection3 = new ArrayCollection(
    array_merge($collection1->toArray(), $collection2->toArray())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download