I have a string like following:
test1, test2, test3, test4,
When I use the implode function on this I get back that there are 5 elements in the array.
How can i not take into account the last extra comma ?
or better yet, how can i substring that so that there is no extra comma in the end.
You can remove trailing commas (or any character) using rtrim();
Try this:
$str = rtrim(‘test1, test2, test3, test4,’, ‘,’);
See the doc for rtrim() @ https://www.php.net/manual/en/function.rtrim.php