Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP开关函数未显示真实结果_Php_Switch Statement - Fatal编程技术网

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;

与其从函数中回显数据,不如将其作为字符串返回