我想让函数merge()
具有变量city和function需要返回在合并索引数组中的值后创建的句子。
function merge() {
$city = array ("Tokyo", "Paris", "Berlin");
$index="";
foreach ($city as $value)
$index = $index. $value. "";
return ("$index");
echo merge();
这是将变量组合成一个变量的正确方法$index = $index. $city. "";
吗?还有另一种方式吗?
答案 0 :(得分:-1)
简单,
function merge() {
$city = array ("Tokyo", "Paris", "Berlin");
$index="";
foreach ($city as $value)
$index .= $value.",";
echo $index;
}
内爆,
function merge() {
$city = array ("Tokyo", "Paris", "Berlin");
$index = implode($city,",");
echo $index;
}