Reputation: 366
I have problem with getting the content. I don't know the names of the post variables so I can't do this using
$variable = $_POST['name'];
because I don't know the "name". I want to catch all of the variables sent by POST method.
How can I get keys of the $_POST[]
array and the corresponding values?
Upvotes: 0
Views: 10777
Reputation: 1
basically post request will be mapped to array. for debuging you can call
var_dump($_POST);
this code will list all array within post array.
Upvotes: 0
Reputation: 4389
Besides print_r($_POST);
you could also use var_dump($_POST);
, but most logical solution as mentioned earlier is foreach
loop.
Upvotes: 0
Reputation: 3274
Just use a for each loop
foreach($_POST as $key => $value){
echo "$key = $value";
}
Upvotes: 0
Reputation: 34347
$_POST is just a big array:
while(list($keys,$vars) = each($_POST)){ // do something. }
Upvotes: 2
Reputation: 284816
Standard for-each:
foreach ($_POST as $key => $value)
{
// ... Do what you want with $key and $value
}
Upvotes: 7