13 Votes

PHP: Iterate all POST-Variables

Question by Guest | Last update on 2021-11-02 | Created on 2015-05-08

I am transmitting a dynamic form using POST to one of my PHP scripts in order to evaluate the data there.

Usually, each POST variable can be retrieved using $_POST['name'] in the script. However, in my case, I need a solution with which I can go through or loop over all POST variables existing without knowing their name or key, because they are created dynamically and can be different each time executing the script.

So, I need something like a foreach for the $_POST variable, which can be otherwise used for an array. The requirement is that I would like to have all values and key names receiving via POST. Is this possible somehow?

ReplyPositiveNegative
5Best Answer5 Votes

You can just apply "foreach" to $_POST, because $_POST is nothing more than an array containing all transmitted values.

Here is a small example:

foreach($_POST as $key => $value) {
  echo "$key = $value"
}

Because $_POST is an associative array, it is possible to read out both, key names (here $key) and values (here $value) in this way, where the key is the name of the input field and the value is the corresponding content of the input field.
Last update on 2021-11-02 | Created on 2015-05-08

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.