What is use of laravel collection implode() function. php array impolde like function in laravel collection. how to change a collection values to comma seperate string.
Laravel collection implode function
laravel collection implode() function work same as php implode function it join collection items by given string and change collection values to string. see below example fruits collection change in comma seperate string.
$collection = collect(['apple', 'mango', 'banana']); $fruits = $collection->implode(', '); dd($fruits); // apple, mango, banana
Read Also : Laravel custom helper facade
Laravel implode() function on array of collection
when our collection have multilevel arrays then pass key name which you want to join
$collection = collect([ ['id' => 1, 'product' => 'phone'], ['id' => 2, 'product' => 'laptop'], ]); $products = $collection->implode('product', ', '); dd($products); // phone, laptop