| Aaron Wagner 2004-11-22, 3:56 pm |
|
try this..
<?
$exception =3D array("var1","var2","var3") // these are the=20
variables I don't
want to catch
$array =3D array(); // the array to put the variables into
while (list($key,$value) =3D each($_POST)) {
if (in_array($key,$exception)){
$$key =3D $value;
}else{
$array =3D array_merge($array, array($key=3D>$value));
} =20
}
?>
$stack =3D array_merge($stack, array("one"=3D>"test"));
Aaron N Wagner
WagnerWebDesign.net
> -----Original Message-----
> From: Rafael Soares [mailto:design_animation@yahoo.com.br]
> Sent: November 22, 2004 10:58
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Insert keys into an array using variables
>=20
>=20
> Hello!
>=20
> I have a script that gets some _POST variables (all, except some ones
> specified in an array) and puts into another array, to use=20
> them in an e-mail
> message later.
>=20
> But the script needs to catch ANY vars, like I don't know=20
> which vars will be
> sent in _POST.
>=20
> This script will show it better:
>=20
> <?
>=20
> $exception =3D array("var1","var2","var3") // these are the=20
> variables I don't
> want to catch
> $array =3D array(); // the array to put the variables into
>=20
> while (list($key,$value) =3D each($_POST)) {
> if (in_array($key,$exception))
> $$key =3D $value;
> else // here is the problem... How can I use the=20
> variable $key to
> add keys into the array??
> $array[$key] =3D $value; // I also tried $array[&$key] =3D
> $value but it didn't work
> }
>=20
> ?>
>=20
> Later in the message, I'll use this loop:
>=20
> <?
>=20
> while (list($field,$data) =3D each($array)){
> $msg .=3D "- " . $field . ": " . $data . "\n";
> }
>=20
> ?>
>=20
> I can't realize how I can do this...=20
>=20
> Thanks in advance.
>=20
> Rafael Soares - Ag=EAnciaM
> Fone: +55 11 4616-1394
> =20
>=20
> --=20
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
>=20
|