Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   $_POST to function (http://www.programmingforums.org/showthread.php?t=8879)

Lich Mar 15th, 2006 10:09 AM

$_POST to function
 
Can I pass everything in $_POST[] into a function? How would I go about that, just function($_POST) or something else? or should it just pass anyways because $_POST is a superglobal

Mocker Mar 15th, 2006 10:17 AM

$_POST is an a global array. You can call any variable in POST by using $_POST['variable'] . You don't need to pass the actual array to a function because all functions should be able to access it.

Lich Mar 15th, 2006 11:42 AM

that's what I wasn't sure of, thank you.

Polyphemus_ Mar 15th, 2006 11:47 AM

I'm not sure you know this already, but you can also access global variables from a function without passing them as an argument:
:

$someGlobalVariable = "A value for a random, global variable";

function aRatherUselessFunction() {
  global $someGlobalVariable;

  echo $someGlobalVariable;
}


Ooble Mar 15th, 2006 12:12 PM

If the function is quite general, and can accept any array, passing $_POST to it should be fine. If it's been created specifically to deal with the $_POST array, as others have said, you can access it from directly within the function.

cool & fit Mar 20th, 2006 3:58 PM

need help with content management system

Ooble Mar 20th, 2006 4:33 PM

Good ta know. Have fun finding it.

DaWei Mar 20th, 2006 4:41 PM

@ cool and fit: what's fit, your body? Your approach isn't, it sucks. Read the forum's rules/FAQ. Read the "How to Post a Question" thread at the top of the C forum. You're a new member -- check out the community before you decide it operates like your little brother's blog. The rules/FAQ also have a link to a "How to ask questions the smart way" document. That's a good one to read, too. Last, but not least, don't hijack another person's thread; particularly if your subject isn't even the same.


All times are GMT -5. The time now is 6:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC