Hi guys, Here I am gonna share how to remove the last comma in a string by using php rtrim function.
The rtrim() function will remove whitespaces or other predefined character from the right side of a string.
Syntax
rtrim(string,charlist)
Example :
$text_with_comma = “1,2,3,4,5,6,7,”;
$removed = rtrim($text_with_comma, ‘,’);
Output :
1,2,3,4,5,6,7
Thanks!