Php how to remove any last commas

wow picture wow · Jun 25, 2010 · Viewed 80.8k times · Source

Example output

1. test,test,test,test,test,
2. test,test,test,,
3. test,test,,,
4. test,,,,,

I tried use implode according to my previous question but It's trim only last comma.

How to remove any last commas?

Answer

Artefacto picture Artefacto · Jun 25, 2010
rtrim('test,,,,,', ',');

See the manual.