![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
|
$_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
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
$_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.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi freelance scripts - http://ryanguthrie.com/index.html |
|
|
|
|
|
#3 |
|
Professional Programmer
|
that's what I wasn't sure of, thank you.
|
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
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;
} |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2006
Posts: 1
Rep Power: 0
![]() |
need help with content management system
|
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Good ta know. Have fun finding it.
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
@ 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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|