Insert keys into an array using variables
| From: | Rafael Soares | Date: | Mon, 22 Nov 2004 15:57:40 +0000 |
| Subject: | Insert keys into an array using variables | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-25014@lists.php.net to get a copy of this message | ||
Hello!
I have a script that gets some _POST variables (all, except some ones
specified in an array) and puts into another array, to use them in an e-mail
message later.
But the script needs to catch ANY vars, like I don't know which vars will be
sent in _POST.
This script will show it better:
<?
$exception = array("var1","var2","var3") // these are the variables I
don't
want to catch
$array = array(); // the array to put the variables into
while (list($key,$value) = each($_POST)) {
if (in_array($key,$exception))
$$key = $value;
else // here is the problem... How can I use the variable $key to
add keys into the array??
$array[$key] = $value; // I also tried $array[&$key] =
$value but it didn't work
}
?>
Later in the message, I'll use this loop:
<?
while (list($field,$data) = each($array)){
$msg .= "- " . $field . ": " . $data . "\n";
}
?>
I can't realize how I can do this...
Thanks in advance.
Rafael Soares - AgênciaM
Fone: +55 11 4616-1394