I have several $_POST variables, they are
$_POST[\'item_number1\']
$_POST[\'item_number2\']
and so on
I need to write a loop tha di
If you must stick with those variable names like item_numberX
foreach (array_intersect_key($_POST, preg_grep('#^item_number\d+$#D', array_keys($_POST))) as $k => $v) {
echo "$k $v \n";
}
or
foreach (new RegexIterator(new ArrayIterator($_POST), '#^a\d+$#D', null, RegexIterator::USE_KEY) as $k => $v) {
echo "$k $v \n";
}
Better to use php's input variable array feature, if you can control the input names.
then php processes it into an array for you.
print_r($_POST['item_number']);