php remove last character from string if comma

Solutions on MaxInterview for php remove last character from string if comma by the best coders in the world

showing results for - "php remove last character from string if comma"
Kinsley
24 Jul 2017
1$string = rtrim($string, ',');
Stefania
15 Jan 2020
1$arrStr = 'Str1, Str2, str3, ';
2echo rtrim($arrStr, ", "); //Str1, Str2, str3
3echo substr_replace($arrStr, "", -2); //Str1, Str2, str3
4echo substr($arrStr, 0, -2); // Str1, Str2, str3