Ant*_*les 6 php laravel laravel-5 laravel-5.2 laravel-5.3
我有这个Laravel 5.3小巧的系列:
Collection {#325 ?
#items: array:8 [?
0 => 2638
1 => 2100
2 => 5407
3 => 2970
4 => 4481
5 => 1611
6 => 5345
7 => 50
]
}
Run Code Online (Sandbox Code Playgroud)
我想要只在字符串中组合值,我需要这个:
"2638,2100,5407,2970,4481,1611,5345,50"
Run Code Online (Sandbox Code Playgroud)
小智 9
使用implode https://laravel.com/docs/5.3/collections#method-implode
如果$ collection是您显示的值
dd($collection->implode(',')); 应该给出预期的结果
您可以在集合上使用 PHPimplode()或 Laravel->implode()方法:
implode(',', $collection->toArray());
$collection->implode(',');
Run Code Online (Sandbox Code Playgroud)