PHP Iterate through $_POST and use values by name

前端 未结 4 1455
醉酒成梦
醉酒成梦 2021-02-05 05:14

I have a form that contains a number of fields with names item1, item2, item13, item43 etc, each time those fields are different because they are populated in the form with AJAX

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 05:59

    Loop through $_POST and see if the key contains 'item'.

    foreach($_POST as $key=>$value){
        if(preg_match('/item(\d*)/', $key, $match) === 1){
            inserttag($value, $match[1]);
        }
    }
    

提交回复
热议问题