This array holds a list of items, and I want to turn it into a string, but I don’t know how to make the last item have a &/and before it instead of a comma.
1 => coke 2=> sprite 3=> fanta
should become
coke, sprite and fanta
This is the regular implode function:
$listString = implode(', ', $listArrau);
What’s an easy way to do it?
A long-liner that works with any number of items:
Or, if you really prefer the verboseness:
The point is that this slicing, merging, filtering and joining handles all cases, including 0, 1 and 2 items, correctly without extra
if..elsestatements. And it happens to be collapsible into a one-liner.