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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners