我有像
这样的PhP变量<?php
$query=mysql_query("SELECT * FROM visited_city WHERE username='$user' LIMIT 3");
while($row=mysql_fetch_assoc($query)){
$city=$row['city'];
echo '<a href="'.$city.'">'.$city.', </a>';
}
?>
结果=
Dhaka,Delhi,Mumbai,
实际上,我想要
达卡,德里,孟买
对不起,我发现有很多答案,但与我不相符......
答案 0 :(得分:1)
假设城市列表是一个数组$ cities然后
<?php
$counter = 0;
// the list of cities to be printed
$list = "";
foreach($cities as $city) {
if($counter == count($cities)) {
$list.= $city;
} else {
$list.= $city.",";
}
$counter++;
}
echo $list;
?>