cooldude832 Posted June 8, 2007 Share Posted June 8, 2007 lets say i have a group of functions: function form_process_1() function form_process_2() function form_process_3() function form_process_4() function form_process_5() my question is this if i want to call the function by saying $var = form_process_.$i.($_REQUEST) can I do that if the number of variables in $_REQUEST is variable? will that result in parameter errors? if it is I got a way around it be it be very nice. Alternatively can i just call the $_REQUEST Variables in side the function without having to list as parameters since they are "global" in scope? Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/ Share on other sites More sharing options...
btherl Posted June 8, 2007 Share Posted June 8, 2007 $_REQUEST is a single array, so that will work fine. Just make sure your functions expect an array as input. Yes, $_REQUEST is "superglobal", so you can access it anywhere. So no need to pass it around. Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270508 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Author Share Posted June 8, 2007 okay follow up i need to return the values out of the function can i say $var = function() and the function has the line return $field where $field is an array? Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270512 Share on other sites More sharing options...
btherl Posted June 8, 2007 Share Posted June 8, 2007 Yes that will work. $var will be the array returned from function() Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270516 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Author Share Posted June 8, 2007 thanks, I think I've got this under control. I might sound stupid here again, but now that i got $var i have a second function later down and since count($var) will vary how can i use the values in $var in function_2_$i()(there are variable function_2_$i)? can i say function2($var)? It shouldn't matter if I declare parameters for function_2_$i right? because count($var) will be the same always? or is there a way i can make $var into a global scope variable to recollect it in the function and screw this parameter junk? Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270519 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Author Share Posted June 8, 2007 i just read a bit on globals on php freak and since $var is in the root of the p hp doc (Not in a function) can i simply say in my function_2_$i $GLOBALS['var']? Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270520 Share on other sites More sharing options...
btherl Posted June 8, 2007 Share Posted June 8, 2007 Here's an example: $var = 'foo'; function kitten() { global $var; print "var has value $var\n"; } Using $_GLOBALS will work the same way, except it's longer to type each time you use it Regarding all your functions, I'm not sure that's the best way to structure your code. What is the problem you are trying to solve (the programming task) ? Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270522 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Author Share Posted June 8, 2007 I have a page that will process a form that is used for placing an ad on a website. The ad types vary thus the incoming form fields will vary. What happens is i have an inital switch that reads a $_POST with adtype in it. Then from there it decides what function to do for processing the variables. It does this then a bit of html come in the doc then later on I have a block where i need those processed variables redisplayed. The displays too vary with the ad types so thus I use the return of function_1 in the displaying in function 2. I think the global scope idea will work here because as soon as i get in function 2 i'll say $values = $_GLOBAL['var']; and then work of the multi-d array $values. I could work around using 2 functions and have the html block be echoed out in each function. but the person i'm doing this for whats that html block for SEO reasons. also this page is in a log in only part of the site so the error message happens and needs that html block also. Quote Link to comment https://forums.phpfreaks.com/topic/54698-question-about-function-paramters/#findComment-270529 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.