php 如何从 $_POST 获取键值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/183914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:49:48  来源:igfitidea点击:

How do I get the key values from $_POST?

phparrays

提问by Haabda

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?

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

采纳答案by theraccoonbear

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

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

http://us2.php.net/array_keys

http://us2.php.net/array_keys

回答by Mark Biek

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

$_POST 只是一个普通的关联数组,所以你也可以像这样循环整个事情:

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

回答by theraccoonbear

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

@Tim:有一个)失踪。所以应该是:

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

回答by Tim

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

回答by U?ur Gümü?han

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.

回答by Matthias Winkelmann

array_keys($_POST)

Manual

手动的