php - Remove last character from a string -
i have list of country array .. want array in following format later return via ajax :-
"india","usa","uk" ..
used following code looking ..
foreach($country_list $country) { $countries .= '"'.$country['label'].'",'; } problem is giving output "india","usa","uk", ... i.e trailing comma .
tried remove with
substr_replace($countries, "0", -1); and
rtrim($countries, ","); but didnt work ! .. please !
i think you're missing assign variable after trim:
$s = '"india","usa","uk",'; $s = rtrim($s, ','); // prints "india","usa","uk" print $s; demo
Comments
Post a Comment