PHP:在数组中存储多个选择值

时间:2015-07-17 09:17:22

标签: php arrays

最多有8个<select name="a">,我需要将这些值存储在数组中

$a = $_POST['a'];
$b = $_POST['b'];

if (isset($a, $b)) {
    foreach ($products as $thisProduct) {
        if ($thisProduct->getId() == $a) {
        //do something & store in array
            switch($b){
                case "one":
                //do something
                break;

                case "two":
                //do something
                break;

                case "three":
                //do something
                break;
            }
        }
    }
}
//call array and make array_sum()...

如何将这些存储在数组中,以便我可以使用此数组进行计算?

更新

还有8个input字段,其中包含金额。此input乘以$a的值。

foreach ($products as $thisProduct) {

    foreach ($a as $value) {
        if ($thisProduct->getId() == $value) {
            $multiply = ($thisProduct->getMultiply($amount));
            array_push($array, $multiply);  
        }
    }
}

如何将每个inputselect name="[a]"

相关联

1 个答案:

答案 0 :(得分:1)

使用<select name=a[]>并使用此代码

$a = $_POST['a'];
foreach($a as $value){
   // do something
}
相关问题