问题
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?
回答1:
rtrim('test,,,,,', ',');
See the manual.
回答2:
rtrim for example:
$str = 'foo,bar,blah,bleh,';
echo rtrim($str,',');
// foo,bar,blah,bleh
回答3:
completely different way:
$str = "1,2,3,4,";
$str = substr($str,0,strlen($str)-1);
来源:https://stackoverflow.com/questions/3120398/php-how-to-remove-any-last-commas