Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

How to remove last comma in string using php

by
Category:php
php
How to remove last comma in string using php

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,',');

0 Comments


Html code work in comment box


Related Post