Associative array key as a variable
| From: | ejfs at sympatico dot ca | Date: | Sat, 23 Feb 2002 17:31:27 +0000 |
| Subject: | Associative array key as a variable | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-85944@lists.php.net to get a copy of this message | ||
Hi.
I have the following PHP program executed from an HTML form where I pass
the associative array key name as a variable:
<?
function show($name)
{
$cnt = count($HTTP_POST_VARS[$name]);
echo "Count for $name is $cnt";
echo "<br />";
}
show("countries");
show("cities");
?>
The result is always 0. The form fields do have name=countries[] and
name=cities[] to indicate an array.
When I hardcode the count line in the function as follows just to test
to make sure the transfer from the browser works, it displays a correct
non-zero result:
$cnt = count($HTTP_POST_VARS["cities"]);
I even tried these statements in the function but all give a 0 result:
$cnt = count($HTTP_POST_VARS["".$name.""]);
How do I get the count line to work with a variable in the function?
Thanks,
Eurico