【发布时间】:2017-02-22 13:29:42
【问题描述】:
我想在 laravel 5.3 中合并两个数组。我有返回变量 '$type'
`Illuminate\Support\Collection Object ( [items:protected] => Array ( [1] => rinu )`
从查询中得到
$type0=DB::table('users')->where('name','=',$head)->pluck('name','id');
我想与返回的数组 $type1 合并
Illuminate\Support\Collection Object ( [items:protected] => Array ( [2] => john ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( [3] => dinesh ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( [4] => mahesh ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( ) )
$type1=DB::table('users')->where('name','=',$head)->pluck('name','id');
我尝试将其合并并存储在 $type0 中;
$type0=$type0->merge($type1);
返回错误的值
Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => rinu [1] => john ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => rinu [1] => john [2] => dinesh ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => rinu [1] => john [2] => dinesh [3] => mahesh ) )
Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => rinu [1] => john [2] => dinesh [3] => mahesh ) )`
enter code here
【问题讨论】: