如果我在 html 表单中使用数组,如何从 $_POST 获取变量?
我知道这是不正确的,但这是我最好的猜测:
$item = $_POST[$key]; $price = $_POST[$value];
<?php
// array begins
$database = array(
'Sportscar' => array(
'price' => 11.95,
'shipping' => 0.4,
'ID' => 1),
'Diamonds' => array(
'price' => 44.99,
'shipping' => 0.10,
'ID' => 4),
);
?>
<p>Select an item from the list.</p>
<form method="GET" action="add.php">
<select name="choices">
<? while(list($key,$value) = each($database)) {
echo "<option value='$key'>" . $key . " - " ;
while(list($key,$value) = each($value)) {
echo money_format("$%i", $value);
echo "</option>"; }} echo "</select>
<input type='submit' value='Add to cart' />
</form>
?>