Heya! I’m struggling to find a way to remove a trailing comma from the end of my filter list. Currently its outputting like this:
tag1, tag2, tag3,
But i’d like to to display as:
tag1, tag2, tag3
I’ve tried using $filters->last()); but I understand that only works for Structure and Collections… Is there some way to detect that this is the last tag in the array and remove the comma?
This is a common task in programming: You want to join the elements of a given array to a string, separated by another arbitrary string. Additionally you want to manipulate all the elements of the array by the same way.
The first task is done with PHP’s implode function, the second with array_map. In the end, your foreach loop can be replaced with: