How to display an array to comma separated values with a last “and” by Frédéric Bouchery.

<?php

declare(strict_types=1);

$array = ['a','b','c','d','e'];
echo implode(', ', array_slice($array, 0, -1)) . ' and ' . end($array);