Laravel collection join() method

What is use of laravel collection join method. How to work collection join in laravel 8, laravel 9, laravel 10.


Laravel collection join() function

laravel join() function joins a string with collection values. join() function first argument specify to append given string between items and second argument(optional) use to append before collection final item. see below example

collect(['a', 'b', 'c'])->join(', '); // 'a, b, c'
collect(['a', 'b', 'c'])->join(', ', ', and '); // 'a, b, and c'
collect(['a', 'b'])->join(', ', ' and '); // 'a and b'
collect(['a'])->join(', ', ' and '); // 'a'
collect([])->join(', ', ' and '); // ''
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links