I'd like to pull all the names of fields from a submitted form, and create variables from them automatically. Not much of a problem as my code1 below shows. BUT I'd now like to put the code in a function that I can call from many PHP form processors, and have the newly created variables be accessible in the CALLING context. My code2 below is the best I can do; is there a safer, better way???
CODE1:
foreach($_POST as $key => $value){
$$key = filter_var($value, FILTER_SANITIZE_STRING);
}
unset($key,$value);
CODE2: (resides in included file)
function test(){
foreach($_POST as $key => $value){
global $$key; <<<------ my best attempt
$$key = filter_var($value, FILTER_SANITIZE_STRING);
}
unset($key,$value);
}