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 Quote 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". Quote 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!! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.