To remove/trim the last/trailing or first/heading comma from a string, one should first confirm that the last character of the string is comma itself and nothing else. This would make the code foolproof and prevent accidental removal of characters other than comma.
$string = "'apple', 'car', 'ball',";
$output = rtrim($string,',');