如何在php中找到多维数组中的Name [duplicate]

时间:2021-08-16 21:31:11

This question already has an answer here:

这个问题在这里已有答案:

Is there a way to get the names of the form fields from $_POST ?

有没有办法从$ _POST获取表单字段的名称?

I know I can get the values with $_POST['foo'], but how do I get the list of names (not sure what they are called).

我知道我可以使用$ _POST ['foo']获取值,但是如何获取名称列表(不确定它们的名称)。

Any help is great.

任何帮助都很棒。

3 个解决方案

#1


$_POST is an associative array. Use array_keys to get the keys of the array.

$ _POST是一个关联数组。使用array_keys获取数组的键。

$names = array_keys($_POST);

#2


As simple as that

就如此容易

print_r($_POST);

print_r — Prints human-readable information about a variable

print_r - 打印有关变量的可读信息

http://php.net/manual/en/function.print-r.php

#3


An array consists of array key and value.

数组由数组键和值组成。

$array = array('color1' => 'red','color2' => 'blue', 'color3' => 'green');

to get the key values use

获取关键值使用

$keys = array_keys($array);
print_r($keys);

#1


$_POST is an associative array. Use array_keys to get the keys of the array.

$ _POST是一个关联数组。使用array_keys获取数组的键。

$names = array_keys($_POST);

#2


As simple as that

就如此容易

print_r($_POST);

print_r — Prints human-readable information about a variable

print_r - 打印有关变量的可读信息

http://php.net/manual/en/function.print-r.php

#3


An array consists of array key and value.

数组由数组键和值组成。

$array = array('color1' => 'red','color2' => 'blue', 'color3' => 'green');

to get the key values use

获取关键值使用

$keys = array_keys($array);
print_r($keys);