我有像这样的html:
<form method="post" id="volunteer" name="volunteer" action="<?php echo $PHP_SELF;?>">
<select name="Rank[]" id="Rank">
<option value="0">Please select</option>
<option value="High Priority">High Priority</option>
<option value="Medium Priority">Medium Priority</option>
<option value="Low Priority">Low Priority</option>
</select>
</br>
<select name="Rank[]" id="Rank">
<option value="0">Please select</option>
<option value="High Priority">High Priority</option>
<option value="Medium Priority">Medium Priority</option>
<option value="Low Priority">Low Priority</option>
</select>
</br>
<select name="Rank[]" id="Rank">
<option value="0">Please select</option>
<option value="High Priority">High Priority</option>
<option value="Medium Priority">Medium Priority</option>
<option value="Low Priority">Low Priority</option>
</select>
<input type="submit" value="Submit">
</form>
后面的 PHP 代码,我试图从所有控件中获取所有 Rank 值:
$rank = $_POST['Rank'];
echo "<pre>";
print_r($rank);
echo "</pre>";
$output = "";
foreach($rank as $selected_value)
{
if($selected_value != "0") {
$output .= $selected_value . "<br />";
}
}
但是在第一次提交时,我的$output是空的。如果我在浏览器上单击“返回”并重新提交表单,我实际上会得到非空数组和输出。
请指教!