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?
PHP: array_keys() function The array_keys() function is used to get all the keys or a subset of the keys of an array. Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.
If you want to access the key of an array in a foreach loop, you use the following syntax: foreach ($array as $key => $value) { ... }
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post".
The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.
$_POST is just a normal associative array so you can also loop over the entire thing like this:
foreach($_POST as $key=>$value)
{
echo "$key=$value";
}
Check out the array_keys() function assuming this is PHP.
http://us2.php.net/array_keys
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With