How to merge two php Doctrine 2 ArrayCollection()

Posted by Throoze on Stack Overflow See other posts from Stack Overflow or by Throoze
Published on 2012-04-10T04:37:31Z Indexed on 2012/04/10 5:28 UTC
Read the original article Hit count: 1616

Is there any convenience method that allows me to concatenate two Doctrine ArrayCollection()? something like:

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

$collection1->add($obj1);
$collection1->add($obj2);
$collection1->add($obj3);

$collection2->add($obj4);
$collection2->add($obj5);
$collection2->add($obj6);

$collection1->concat($collection2);

// $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.

Thanks!

© Stack Overflow or respective owner

Related posts about php5

Related posts about symfony-2.0