Source: www.amitmerchant.com

The new Arr::join() method in Laravel 9.x
A while back, I have written an article on https://www.amitmerchant.com/how-to-convert-arrays-to-human-readable-lists-in-javascript/. It’s a built-in feature using the Intl.ListFormat object that lets you do that.

const books = [ 'Harry Potter', 'Bhagavad Gita', 'The Alchemist', 'Birthday Girl' ]

$books = [ 'Harry Potter', 'Bhagavad Gita', 'The Alchemist', 'Birthday Girl' ]; And if we want to deflate it as a human-readable list, here’s how we can do it. use Illuminate\Support\Arr; $bookList = Arr::join($books, ', ', ' and '); // Harry Potter, Bhagavad Gita, The Alchemist and Birthday Girl
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners