获取发布变量的名称

编程入门 行业动态 更新时间:2024-10-26 10:30:59
本文介绍了获取发布变量的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: PHP $ _POST打印变量名称以及值

Possible Duplicate: PHP $_POST print variable name along with value

我有一个表单(无论字段数如何)..该表单将发送$ _POST数据..我想返回每个$ _POST变量值和名称.

I have a form (whatever number of fields).. this form will send $_POST data.. I want to return every $_POST variable value and name.

我想做这样的事情:

foreach($_POST as $field){ //****some code*****// }

以一种显示如下字段和值的方式:

in a way that will display the fields and values like this:

名称:Simo Taqi 电子邮件:example@ymail

name : Simo Taqi email : example@ymail

换句话说:

如果我有一个post变量:$ _POST ['city'] ='拉斯维加斯'

if I have a post variable : $_POST['city']='las vegas'

我想知道如何获取变量的名称:"city".

I want to know how to get the name of the variable : 'city'.

推荐答案

$_POST被填充为关联数组,因此您可以执行以下操作:

$_POST is populated as an associative array, so you can just do this:

foreach ($_POST as $name => $val) { echo htmlspecialchars($name . ': ' . $val) . "\n"; }

此外,如果您只对字段名称感兴趣,则可以使用array_keys($_POST);返回$_POST中使用的所有键的数组.您可以使用这些键来引用$_POST中的值.

Additionally, if you're just interested in the field names, you can use array_keys($_POST); to return an array of all the keys used in $_POST. You can use those keys to reference values in $_POST.

foreach (array_keys($_POST) as $field) { echo $_POST[$field]; }

  • foreach文档
  • array_keys文档
    • foreach documentation
    • array_keys documentation

更多推荐

获取发布变量的名称

本文发布于:2023-10-12 01:17:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!