Php Laravel 5.1循环和合并集合
我尝试在循环时将值合并到一个集合中 这是我目前的设置Php Laravel 5.1循环和合并集合,php,arrays,laravel,collect,Php,Arrays,Laravel,Collect,我尝试在循环时将值合并到一个集合中 这是我目前的设置 $collection = collect([]); foreach($array as $item){ $temp = $item->do_something; !is_null($temp) ? $collection->merge($temp) : null; } $temp可以容纳的内容如下: array['records'=>$array,'details'=>$array] 现在我得到的最接近的是
$collection = collect([]);
foreach($array as $item){
$temp = $item->do_something;
!is_null($temp) ? $collection->merge($temp) : null;
}
$temp可以容纳的内容如下:
array['records'=>$array,'details'=>$array]
现在我得到的最接近的是$temp值的$array,但我想将所有这些值合并到一个集合中。我想要一个包含记录和详细信息的集合,而不是$temp数组
谢谢
更多详细信息我看到了什么:
[0]=> ['records' => $array
'details' => $array]
[1]=> ['records' => $array
'details' => $array]
[2]=> ['records' => $array
'details' => $array]
我想要的是将所有这些合并为一个
['records' => $array, 'details' => $array]