This problem is much better solved by changing the names of the elements in your form to code[].
For example, where you now have let's say
<input type="text" name="code_1" ... />
<input type="text" name="code_2" ... />
<input type="text" name="code_3" ... />
You would change that to
<input type="text" name="code[]" ... />
<input type="text" name="code[]" ... />
<input type="text" name="code[]" ... />
After doing this, $_GET['code'] will be an array which contains all the values from the text boxes as its items.
Update:
If you cannot control the names of the incoming parameters, you need to parse manually. Here's how I would do it:
// Sample data
$get = array('code_1' => 'foo', 'code_2' => 'bar', 'code_X' => 'X', 'asdf' => 'X');
$codes = array();
foreach($get as $k => $v) {
// Reject items not starting with prefix
if (substr($k, 0, 5) != 'code_') {
continue;
}
// Reject items like code_X where X is not all digits
$k = substr($k, 5);
if (!ctype_digit($k)) {
continue;
}
$codes[$k] = $v;
}
print_r($codes);