遍历 $_POST 数组以显示字段名称
有没有办法遍历 $_POST 等数组来查看字段名称而不仅仅是值。为了查看这些值,我做了这样的事情。
foreach ($_POST as $value){
echo $value;
}
这将显示值 - 但我还想显示该数组中的名称。如果我的 $_POST 值类似于 $_POST['something'] 并且它存储了 55;我想输出“东西”。
我有几个需要这个的选定字段。
Is there a way to traverse an array such as $_POST to see the field names and not just the values. To see the values I do something like this.
foreach ($_POST as $value){
echo $value;
}
This will show me the values - but I would like to also display the names in that array. If my $_POST value was something like $_POST['something'] and it stored 55; I want to output "something".
I have a few select fields that I need this for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的意思是这样吗?
如果您只想要一个数组,您也可以使用
array_keys
迭代的键。如果您想使用回调迭代:
You mean like this?
you can also use
array_keys
if you just want an array of the keys to iterate over.You can also use
array_walk
if you want to use a callback to iterate:或者使用 array_keys 从数组中获取所有键。
Or use array_keys to fetch all the keys from an array.
如果您只想要键:
或者...
如果您想要键和值:
If you just want the keys:
Or...
If you want both keys and values:
仅针对键:
输出它们:
-或者-
For just the keys:
Output them with:
-or-