PHP字符串运算符 - 与Function()结合使用

时间:2016-09-14 10:33:14

标签: php function operators

我想结合使用function(),并用字符串运算符回显它。

这种用法的原因是我构建了一个包含多个下拉菜单的html / php表单,其中只有名称不同。 我使用while / if / else语句对我的SQL查询使用字符串运算符。

功能:

function telling($setname) 
    {
        echo "<select name=".$setname.">";
        foreach (range(0, 35) as $number) 
        {               
                echo "<option value=".$number.">".$number."</option>\r\n";  
        }
        echo "</select>";
    }

输出:

$output "";
$output .= "<form>";
telling("set1_1");
$output .= "  -  ";
telling("set1_2");
....
$output .= "</form>";
echo $output;

我确实在网站上获得了下拉菜单,但是在网站上的其他部分是按预期的。 你们知道如何结合我的方法。

1 个答案:

答案 0 :(得分:0)

function telling($setname) 
{
    $html = "<select name=".$setname.">";
    foreach (range(0, 35) as $number) 
    {               
            $html .= "<option value=".$number.">".$number."</option>\r\n";  
    }
    $html .= "</select>";
    return $html;
}

并且还要改变

$output = "";
$output .= "<form>";
$output .= telling("set1_1");
$output .= "  -  ";
$output .= telling("set1_2");
....
$output .= "</form>";
echo $output;