tags:

views:

1146

answers:

5
echo $_POST["name"]; //returns the value a user typed into the "name" field

I would like to be able to also return the text of the key. In this example, I want to return the text "name". Can I do this?

A: 
array_keys($_POST)

Manual

MattW.
+10  A: 

Check out the array_keys() function assuming this is PHP.

http://us2.php.net/array_keys

theraccoonbear
+3  A: 

$_POST is just a normal associative array so you can also loop over the entire thing like this:

foreach($_POST as $key=>$value)
{
  echo "$key=$value";
}
Mark Biek
A: 
while( list( $field, $value ) = each( $_POST ) {
   echo "<p>" . $field . " = " . $value . "</p>\n";
}
Tim
+1  A: 

@Tim: there was a ) missing. so it should be:

while( list( $field, $value ) = each( $_POST )) {
   echo "<p>" . $field . " = " . $value . "</p>\n";
}