How do I remove the last comma from a string using PHP?

You may use the rtrim function. The following code will remove all trailing commas:

rtrim($my_string, ',');

The Second parameter indicates characters to be deleted.

Leave a Comment