Renaming Variables in Foreach [Solved]
Posted: Tue Jan 17, 2006 11:16 am
I have a form that posts the data, which the next page gathers. The variables are never redeclared, so they remain the exact names from the form. I wanted to see if I could change the variable using a foreach statement on the _POST array. Something such as adding a number to the end of each variable name. For instance, chaning $name to $name1 and $email to $email1. I attempted this and got nothing but errors in my syntax, and can't find any examples online or in my books about changing a variable name like this. I was using this code:
Note the varaible $valueEXTRA is what I am trying to change to $value1. I do not actually use the EXTRA part, thats to make it easy to see what part I am talking about. I can't figure out add a number to the end, or if it is even possible.
I'm not even sure the $_POST[$key] = $value; is nessessary, but I was going to test that after I got the renaming part functioning.
Code: Select all
function rename_post() {
foreach ($_POST as $key => $value) {
$_POST[$key] = $value;
$valueEXTRA = $value;
}
}I'm not even sure the $_POST[$key] = $value; is nessessary, but I was going to test that after I got the renaming part functioning.