NickG21 Posted May 26, 2009 Share Posted May 26, 2009 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 Link to comment https://forums.phpfreaks.com/topic/159740-solved-variable-name-from-for-each-_post-command/ Share on other sites More sharing options...
Maq Posted May 26, 2009 Share Posted May 26, 2009 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". Link to comment https://forums.phpfreaks.com/topic/159740-solved-variable-name-from-for-each-_post-command/#findComment-842561 Share on other sites More sharing options...
NickG21 Posted May 26, 2009 Author Share Posted May 26, 2009 excellent, thank you!! Link to comment https://forums.phpfreaks.com/topic/159740-solved-variable-name-from-for-each-_post-command/#findComment-842568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.