For Programmers: Free Programming Magazines  


Home > Archive > PHP on Windows > November 2004 > RE: [PHP-WIN] Insert keys into an array using variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-WIN] Insert keys into an array using variables
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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com