【发布时间】:2014-12-31 06:12:39
【问题描述】:
我的表单有几个字段,其中三个具有从 1 到 5 的数字选项。
假设我有以下选择器:
$Cake= intval($_POST["Cake"]);
$Candy= intval($_POST["Candy"]);
$Box= intval($_POST["Box"]);
那么我怎样才能对上述字段值进行计数并返回如下响应:
//Box has 1 selected and Cake has 2 selected
array_push($box,array("paxType" => "Cake"), array("paxType" => "Cake"));
//Box has 2 selected and Cake has 3 selected and Candy has 1 selected
array_push($box,array("paxType" => "Cake"), array("paxType" => "Cake"));
array_push($box,array("paxType" => "Cake"), array("paxType" => "Candy"));
等等。
我知道我需要制作如下的计数公式和 if 规则(它不正确,但我输入它以显示我需要做的一些事情)
if ( count($Box) == 2 count($Cake) == 4)
array_push($box,array("paxType" => "Cake"), array("paxType" => "Cake"));
array_push($box,array("paxType" => "Cake"), array("paxType" => "Cake"));
每个盒子最多只能包含 2 个蛋糕和 2 个糖果。 例1
- 搜索:BOX ->2;蛋糕 ->4
- 结果:BOX(1) ->2 个蛋糕;盒子(2)-> 2 蛋糕;
Ex2
- 搜索:BOX ->2;蛋糕 -> 4 ;糖果->1
- 结果:BOX(1) ->2 个蛋糕; BOX(2) -> 2 个蛋糕和糖果 ->2;
我怎样才能让这个 make 工作? 非常感谢您的宝贵时间,祝您新年快乐。
【问题讨论】:
-
您不应该在比较操作中使用 == 而不是单个 = 吗?更多信息请参考此链接:link
-
您的 if 语句在您的两个计数测试之间也缺少逻辑运算符。我无法确切地弄清楚您要完成什么...但是您需要在两者之间使用
&&或||。除此之外,请编辑以解释您要做什么...