如何:将Laravel集合折叠成逗号分隔的字符串?
dd($ids);
Illuminate\Support\Collection {#538 ▼
#items: array:463 [▼
0 => 30578786410269
1 => 30578326028621
2 => 30788548304669
3 => 30788548607437
4 => 30788592370221
5 => 30788592672989
6 => 30788592975757
7 => 30492511411997
]
}
我如何将其转换为类似的字符串?:
30578786410269,30578326028621,30788548304669,30788548607437,30788592370221,30788592672989,30788592975757,30492511411997
答案 0 :(得分:2)
使用implode
提供的Illuminate\Support\Collection
方法:
$imploded = $collection->implode(',');
Laravel 6.x Docs - Collections - Available Methods - implode
答案 1 :(得分:0)
您可以使用implode()
$data = $collection->implode(','); // returns string
或,您可以将collection
转换为array
$data = $collection->toArray(); // returns array