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?
$_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";
}
Check out the array_keys() function assuming this is PHP.
@Tim: there was a )
missing. so it should be:
while( list( $field, $value ) = each( $_POST )) {
echo "<p>" . $field . " = " . $value . "</p>\n";
}
while( list( $field, $value ) = each( $_POST )) {
echo "<p>" . $field . " = " . $value . "</p>\n";
}
foreach($_POST as $rvar)
{
$rvarkey=key($_POST)
$$rvarkey=mysql_real_escape_string($rvar);
}
it creates variables having the name of the request parameters which is pretty awesome.
array_keys($_POST)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.