如何在HTML中绑定数量(类型编号的输入)和项目(类型复选框的输入)?

I have a list of dynamically generated items (in PHP) and I have to let the user to chose a quantity for each item, how can I bind (and distinguish) each input of type number to corresponding item? Each item has a code as attribute "value" and I could give names (attribute "name") like "numitems_".$itemcode to input tags of but I'm not sure this is a clean solution.

There are several ways of doing this.

I would set the name of the inputs to an array:

echo '<input type="number" name="numitems['.$itemcode.']" />';

Then you can check it like this:

foreach($_POST['numitems'] as $code => $number){
  echo 'Value of '.$code.' is: '.$number;
}