Jump to content

[SOLVED] Retrieve everything form post


Bendude14

Recommended Posts

Could someone please tell me what would be the easiest way to retrieve everything from a post array.

 

so instead of

 

$var1 = $_POST['var1']
$var2 = $_POST['var2']
$var3 = $_POST['var3']
$var4 = $_POST['var4']
$var5 = $_POST['var5']

 

something like this?

 

foreach($_POST as $var) { for($i=0; $var[$i]; $i++) { $var = $_POST[$var[$i]]; } }

 

 

the information been posted is var1, var2, var3 etc

 

Thanks

Link to comment
Share on other sites

$_POST['var1'], $_POST['var2'], ... are already variables. Making a copy into $var1, $var2, ... is a waste of memory and processor cycles. Doing what you want would require using variable variables, which are three times slower than just accessing the array variable itself.

 

Just use the foreach() loop to iterate over each element and do what ever you want with the key/value pairs inside the loop -

 

foreach($_POST as $key => $value) {
    echo $key . $value; // process each key/value as needed
}

 

If the form fields var1, var2,... are actually a set of same type values, it is also much easier to make them an array with some base name and then you can iterate over that array using a foreach() loop as well.

 

If that does not accomplish what you need in your code, explain exactly what you are doing or provide actual code and someone can provide direction on how to do it.

 

 

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.