【发布时间】:2017-11-25 00:50:32
【问题描述】:
我正在尝试使用单选插入多个值,这是我的示例:
<input type="radio" name="toppingPrice[]" value="<?= $topping['name'];?>-<?= $topping['price'];?>">
如果我插入单个输入,这一项工作,但如果我想插入多个例如:
Size: small, medium, large <- name="toppingPrice[]" for all input values
Cheese: yes, no <- name="toppingPrice[]" for all input values
Level: spicy, normal <- name="toppingPrice[]" for all input values
这不起作用,因为它会合并到 1 个组中,所以如果我必须只选择所有浇头中的一个。
我的原始代码如下所示:
foreach ($toppingPrice as $key) {
list($toppingName,$toppingNameEn, $toppingPrice) = explode("-",$key,3);
$tName[] = $toppingName;
$tNameEn[] = $toppingNameEn;
$tPrice += $toppingPrice;
}
$tn = implode(",", $tName);
$tn_en = implode(",", $tNameEn);
$price = $price + $tPrice;
HTML:
<input type="checkbox" name="toppingPrice[]" id="<?= $topping[0];?>" value="<?= $topping['name'];?>-<?= $topping['name_en'];?>-<?= $topping['price'];?>" <? if($topping['price'] < 1){echo "checked";}?>>
我希望我以正确的方式提出问题
请给我任何解决此问题的想法或解决方案
【问题讨论】:
标签: php arrays radio-button