Can I use a generated variable name in PHP?

前端 未结 9 2172
梦谈多话
梦谈多话 2020-12-11 11:50

I have a bunch a values I would like to add together which are entered into a form. Right now, the form has 11 lines but it could get larger in the future. I can easily add

9条回答
  •  春和景丽
    2020-12-11 12:22

    The values you need are posted from a form, right? If so, you could iterate through the keys in the $_POST variable that match your form field's generated names.

    foreach($_POST as $key=>$value)
    {
      if(strpos($key, 'pBalance')===0)
      {
        $final_total += $value;
      }
    }
    

提交回复
热议问题