PHP开关函数未显示真实结果
我有此函数用于显示类型名称:PHP开关函数未显示真实结果,php,switch-statement,Php,Switch Statement,我有此函数用于显示类型名称: function is_typename($type){ switch ($type){ case 1: echo "Bring an extra $500"; break; case 2: echo "Bring an open mind"; break; case 3: echo "Bring 15 bottles of SPF 50 Sunsc
function is_typename($type){
switch ($type){
case 1:
echo "Bring an extra $500";
break;
case 2:
echo "Bring an open mind";
break;
case 3:
echo "Bring 15 bottles of SPF 50 Sunscreen";
break;
case 4:
echo "Bring lots of money";
break;
case 5:
echo "Bring a swimsuit";
break;
}
}
没有显示我拥有的链接:
echo '<a href="'.SITE.''.$lang.'/'.is_typename($type).'/'.$id.'/'.$seotitle.'" rel="nofollow" title="'.$title.'" target="'.$target.'">'.$title.'</a>';
echo';
在行动中,我看到:
Bring an extra $500<a href="http://localhost/cms/en//241/titeltest" rel="nofollow" title="titeltest" target="_blank">titeltest</a>
多带500美元
问题:
$type
和typename显示在外部href
和
中。如何解决此问题?不使用echo,而是使用return
范例
case 1:
return "Bring an extra $500";
break;
与其从函数中回显数据,不如将其作为字符串返回