我需要保持选择用户在多选菜单中选择的选项。这是迄今为止的代码,但仍然不起作用。感谢您的帮助!保持选择多个选项中的选项PHP
<select name="cb_estatura2[]" size="6" multiple="multiple" class="inputbox" id="cb_estatura2">
<?php
$height = array("57","58","59","60");
$choosen_height = $_GET['cb_estatura2'];
for ($i=0;$i<count($height);$i++)
{
$selected = ($height[$i] == $choosen_height[$i] ? 'selected="selected"' : '');
echo "<option value='$height[$i]' $selected>$height[$i]</option>";
}
?>
</select>
您将需要使用in_array来检查密钥($ height [$ i])是否在get变量中。 – Corbin 2011-12-22 04:40:08
我只是猜测,但我不认为你需要在'$ chosen_height'上的'[$ i]''。我很难告诉出更多的信息,但我猜测这只是一个整数而不是数组。 – mikelbring 2011-12-22 04:40:13
运行'print_r($ _ GET ['cb_estatura2']);'并发布它说的内容。 – Blender 2011-12-22 04:40:27