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

try before buy


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -