loop through $_POST variables with similar names

后端 未结 7 805
南笙
南笙 2020-12-18 09:51

I have several $_POST variables, they are

$_POST[\'item_number1\']
$_POST[\'item_number2\']

and so on

I need to write a loop tha di

7条回答
  •  不知归路
    2020-12-18 10:11

    foreach($_POST as $k => $v) {
        if(preg_match("#item_number([0-9]+)#si", $k, $keyMatch)) {
            $number = $keyMatch[1];
    
            // ...
        }
    }
    

提交回复
热议问题