如何从$ _POST获取键值?

时间:2008-10-08 17:33:08

标签: php arrays

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

我希望能够返回密钥的文本。在这个例子中,我想返回文本“name”。我可以这样做吗?

6 个答案:

答案 0 :(得分:28)

$ _ POST只是一个普通的关联数组,所以你也可以循环遍历整个事情:

foreach($_POST as $key=>$value)
{
  echo "$key=$value";
}

答案 1 :(得分:17)

检查array_keys()函数,假设这是PHP。

http://us2.php.net/array_keys

答案 2 :(得分:5)

@Tim:缺少)。所以它应该是:

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

答案 3 :(得分:3)

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

答案 4 :(得分:0)

array_keys($_POST)

Manual

答案 5 :(得分:0)

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.