Remove last character from a string

I have a list of country as an array .. i want this array in following format to later return it via ajax :- "india","usa","uk" .. Used following code to get somewhat i was looking for .. foreach($country_list as $country) { $countries .= '"'.$country['label'].'",'; } problem is it is giving output like "india","usa","uk", ... i.e with trailing comma . Tried to remove it with substr_replace($countries, "0", -1); and rtrim($countries, ","); But didnt work ! .. Please help !
why not use the implode function? Does exactly what you need and also removes the trailing "comma"

以上就是Remove last character from a string的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准