Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is $_POST writable and an acceptable practice?

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
0
0
US
I have a large set of values that I will need to process in a "POST" loop. Mixed in are a few variables that need to be processed the same way but are not in the POSTed data. For convenience, can I add those variables to the $_POST array and what is the safest/best way to do that? TIA.
 
I don't know what a '"POST" loop' is, but I'll answer as best I can.

The only superglobal array that has any special properties is $_SESSION. $_POST is just an array with an unusual variable scope. You can add more elements to $_POST.

It's probably not a good programming practice, though. Six months from now, you'll be scratching your head for a week trying to figure out how those extra values got in there.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi,
you can add the variables but is not a good practice.

Better: create a copy of $_POST, add the keys which you want to the new variable and process it.

Code:
$c_post = $_POST;
// work with $c_post

Regards


___
____
 
Thanks for the replies. I thought it might be a poor idea but wante dot verify. I'll create a new array and add them there.

P.S. By POST loop what I meant was that I have a while loop that is used to process all the elements of $_POST regardless of how many are there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top