Eliminar la última coma de la cadena PHP
rtrim($my_string, ',');
Indian Gooner
rtrim($my_string, ',');
$string = rtrim($string, ',');
echo substr($string, 0, -2);
//dont print last comma after string print using foreach loop
hasComma = false;
foreach ($this->sinonimo as $s){
if (hasComma){
echo ",";
}
echo '<span>'.ucfirst($s->sinonimo).'</span>';
hasComma=true;
}