Jump to content

[SOLVED] Variable name from For Each $_POST command


NickG21

Recommended Posts

Hey everyone,

      I'm working on some form submission/validation code and I was wondering if there was anywa that using the code below I could set the variable names as well?

 

Right now im just displaying the data;

	foreach ($_POST as $key => $value) {
    echo $key . ":";
    echo $value . "<br/>";
  }

 

Displays like this, properly;

ShipCuFName:nick

ShipCuLName:girard

ShipCuAddr:12 autumn ave

 

but i'd like to be able to assign the actual field name $key(ShipCuFName) is referring to as a variable with the $value (nick)in it without having to individually code it?

thank you in advance!

NickG

Will create the variable name with the value of $key and assign it to the value of $value.  Notice the double '$', make sense?

 

$$key = $value;

 

So if you do this after the loop:

 

echo $ShipCuFName;

 

It will output "nick".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.