chard Posted September 28, 2007 Share Posted September 28, 2007 Hi I'm trying to turn each $_POST into a variable so that I can later assign it a value. Not sure how this can be done. Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/ Share on other sites More sharing options...
hemlata Posted September 28, 2007 Share Posted September 28, 2007 Hello, Please more clarify your issue, so that some one can reply. Better if you give an example with your code. Regards, Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357080 Share on other sites More sharing options...
chard Posted September 28, 2007 Author Share Posted September 28, 2007 Yeah thanks, I was just thinking I was being a bit to vague each $_POST turns into a variable say: $_POST['test'] and $_POST['test1'] get submitted then variable $test and $test1 are created so that if $test and $test1 exist "something","something" can be assigned to them Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357082 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 try foreach($_POST as $key => $value) $$key = $value; Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357105 Share on other sites More sharing options...
chard Posted September 28, 2007 Author Share Posted September 28, 2007 Haven't got it quite to work what am I doing wrong? foreach($_POST as $key => $value) { $$txttest = "DONE"; } echo $$txttest; Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357121 Share on other sites More sharing options...
php_dave Posted September 28, 2007 Share Posted September 28, 2007 The code that sasa wrote is explicit - For example with his code (unchanged) for $_POST vars var1, var2 and var3 you would end up $var1 = "value1" $var2 = "value2" $var3="value3" So would use them as a normal var example Echo $var1; echo $var2; echo $var3; HTH Dave Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357125 Share on other sites More sharing options...
hemlata Posted September 28, 2007 Share Posted September 28, 2007 Hello, yes i agree with php_dave, i think you are looking for something like following script.. <?php $_POST['test'] = 'test'; $_POST['test1'] = 'test1'; foreach($_POST as $key => $value) { $$key = $value; } print_r($test); print_r('<br>'.$test1); ?> Regrds, Quote Link to comment https://forums.phpfreaks.com/topic/71017-solved-foreach-help/#findComment-357129 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.