PHP

How to remove the last comma or character from a string list

How to remove the last comma or character from a string list


How to remove the last comma or character from a string list

You can remove the last comma, or character from a string - which which when you loop through a comma seperated list, can break the loop because the last value is empty after the last comma, so you want to remove it before you loop through the list.

By doing this:

$string = "'name', 'name2', 'name3',";
$string = rtrim($string,',');

Published: 1st June 2016 by

Adverts