Q:

Iterating over all filter_input variables

Using $_POST, I can iterate through all POST variables with
foreach($_POST as $key => $value) {
    // do something
}

But is there anything similar for iterating through every $key such that filter_input(INPUT_POST, $key) gives a variable from POST?
Obiviously I could use
foreach(array_keys($_POST) as $key) {
    if(filter_has_var(INPUT_POST, $key) {
        $value = filter_input(INPUT_POST, $key);
        // do something
    }
}

But this would not always be sufficient. If for example some of the $_POST keys had been unset, it would be useful to find out which keys were originally available, as they would still be accessible through filter_input. Besides, I would like to never have to access any superglobals directly.

A:

I think there is a design problem, using FILTER_INPUT is the same as using SUPERGLOBALS. If you want to unset any $_POST variable, you have to keep a copy of that variable before unset it. There is nothing wrong to parse $_POST as is:
   // backup your $_POST (or $_POST keys)
   $_post_backup = $_POST;

   // remove 'foo'
   unset($_POST['foo']);

   // itereate
   foreach($_post_backup as $key => $value) {
       $filtered_value = filter_input(INPUT_POST, $key);
       // do something
   }

