Azu Posted October 5, 2007 Share Posted October 5, 2007 Hi I'm trying to make some functions to standerdize my form creation, but I'm having some problems. Can somebody please tell me what's wrong with this? function testfunction($a){global $$a;echo $$a;} $ThisWorks='This worked'; testfunction("ThisWorks"); That works fine but.. $_GET['Variable']='Broken'; testfunction("_GET['Variable']"); Isn't working! And I need it to work like this to process form variables! Putting in just plain "echo $_GET['Variable'];" works fine though, so I'm sure it's not that the variable isn't declared. My function does isn't liking _GET for some reason. Please can somebody tell me how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/ Share on other sites More sharing options...
MmmVomit Posted October 5, 2007 Share Posted October 5, 2007 Variable variable names don't work like that. You would need to pass two arguments, one being "_GET" and the next being "Variable", then use one parameter as an index to the array. Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/#findComment-362675 Share on other sites More sharing options...
kathas Posted October 5, 2007 Share Posted October 5, 2007 Try out <?php function testfunction($a){global $$a;echo $$a['variable'];} // and i you dont need the global declaration for _GET testfunction('_GET'); //that will work of course you can use another var in your func to make it dynamic to check ex.: <?php function testfunction($a,$b=FALSE){global $$a;echo ($b) ? $$a[$b] : $$a;} Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/#findComment-362678 Share on other sites More sharing options...
MmmVomit Posted October 5, 2007 Share Posted October 5, 2007 That second one isn't quite right. It will fail if $b is set to '0'. Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/#findComment-362683 Share on other sites More sharing options...
kathas Posted October 5, 2007 Share Posted October 5, 2007 Yeah it was just code to show the logic besides he wont be using this function anyway... Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/#findComment-362688 Share on other sites More sharing options...
Azu Posted October 5, 2007 Author Share Posted October 5, 2007 There we go function testfunction($a){global $_GET;echo $_GET[$a];} Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/71995-solved-functions-for-form-creation/#findComment-362694 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.