How to merge two php Doctrine 2 ArrayCollection()

前端 未结 8 1066
误落风尘
误落风尘 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:08

    Using Clousures PHP5 > 5.3.0

    $a = ArrayCollection(array(1,2,3));
    $b = ArrayCollection(array(4,5,6));
    
    $b->forAll(function($key,$value) use ($a){ $a[]=$value;return true;});
    
    echo $a.toArray();
    
    array (size=6) 0 => int 1 1 => int 2 2 => int 3 3 => int 4 4 => int 5 5 => int 6
    

提交回复
热议问题