<!-- html code -->
<form id="wpsc-settings-form" action="" method="post">
<tr class="rate_row">
<td>
<input type="text" style="width:160px;" value="3000" name="zipcode[]">
</td>
<td>
<select multiple="" name="city[]">
<option value="Abbotsford">Abbotsford</option>
<option value="Aberfeldie">Aberfeldie</option>
<option value="Airport West">Airport West</option>
</select>
</td>
<td>
<input type="text" style="width:160px;" value="3000" name="zipcode[]">
</td>
<td>
<select multiple="" name="city[]">
<option value="Abbotsford">Abbotsford</option>
<option value="Aberfeldie">Aberfeldie</option>
<option value="Airport West">Airport West</option>
</select>
</td>
</tr>
</form>
<!-- php code -->
<?php
$options = $_POST['zipcode'];
$city = $_POST['city'];
$serializeoption = serialize($city);
foreach($city as $key => $value){
$simple_shipping_options_city[$options[$key]] = $value;
}
echo "<pre>";
print_r($simple_shipping_options_city);
echo "</pre>";
update_option('wpsc_simple_shipping_city', $simple_shipping_options_city); // update query
?>
上面的代码按以下方式工作。如果我选择一个城市输出是这样的:
Array
(
[3000] => Abbotsford
[2000] => Airport West
)
如果我选择多个城市不传递输入字段值。
我想针对多个城市保存单个邮政编码。您能否提供上述代码的改进建议?