How to merge two php Doctrine 2 ArrayCollection()

前端 未结 8 1051
误落风尘
误落风尘 2020-12-08 01:21

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

$collection1 = new ArrayCollection         


        
8条回答
  •  情话喂你
    2020-12-08 02:07

    $newCollection = new ArrayCollection((array)$collection1->toArray() + $collection2->toArray()); 
    

    This should be faster than array_merge. Duplicate key names from $collection1 are kept when same key name is present in $collection2. No matter what the actual value is

提交回复
热议问题