我有以下 PHP 函数:
function pick ($fieldname, $optionvalues, $defvalue=0, $size=0)
{
$checked = $defvalue;
echo "<select name=\"$fieldname\" size=\"$size\">\n";
foreach ($optionvalues as $value)
echo " <option value = \"$value\" ".
(($value == $checked) ? ' selected ' : '') . "> $value </option>\n";
echo "</select>";
}
当我用这个调用它时:
$vals = array('a','b','c','d','e');
pick ('pick2', $vals, 'c');
它不会突出显示c
,即使在页面源中,它被标记为选中。我的页面来源是:
<select name="pick2" size="0">
<option value = "a" > a </option>
<option value = "b" > b </option>
<option value = "c" selected > c </option>
<option value = "d" > d </option>
<option value = "e" > e </option>
</select>
如果我将呼叫功能更改为:
pick('p',$vals,'c')
它按预期工作。有人可以解释我的功能有什么问题吗?