我有一个国家列表作为数组..我希望按照以下格式将此数组转换后通过ajax返回:
"印度","美国","英国" ..
使用以下代码可以获得我要找的结果:
foreach($country_list as $country) {
$countries .= '"'.$country['label'].'",';
}
问题在于它输出的结果是像“印度”,“美国”,“英国”等,即带有逗号。尝试使用以下方法去除逗号:
substr_replace($countries, "0", -1);
并且
rtrim($countries, ",");
但是没有起作用!...请帮忙!
$country['label']
。 - insertusernamehere$countries
是数组还是字符串? - Tushar Gupta - curioustushar