Jump to content

Question about function paramters


cooldude832

Recommended Posts

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?

Link to comment
Share on other sites

$_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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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) ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.