php - Using variable in $_POST
I have an HTML form collecting data in which I have a series of fields that repeat for 18 rows (eg name1, name2, names, etc). This data is then passed into a PHP script using POST that processes that data.
What I would like to be able to do is create a loop that increments a counter so that the name field can be regenerated the required number of times. For example, a loop that does:-
$x=1;
$processName = 'name' . $x;
$nameField=$_POST['$processName'];
printf("%s<br>\n",$nameField);
$x++;
This repeats and outputs each of the name fields from the initial form. Can this be done?
Answer
Solution:
This should solve your problem.
foreach ($_POST as $param_key => $param_val) {
echo "name" . $param_val . "<br />\n";
}
Source