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
https://forums.phpfreaks.com/topic/123883-solved-retrieve-everything-form-post/
Share on other sites

i already did. suppose i should have mentioned that i just get a heap of undefined indexes.

 

also my code  would only assign the $_POST[$var[$i]] to $var when i need it to assign to var1, var2 etc

 

hope this makes sense.

 

 

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.