Re: Creating Dynamic Variables
| From: | Michael Sims | Date: | Thu, 18 Jul 2002 02:54:43 +0000 |
| Subject: | Re: Creating Dynamic Variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108202@lists.php.net to get a copy of this message | ||
On Wed, 17 Jul 2002 22:39:10 -0400, you wrote:
>Hello, I have captured variables from any HTML that is POSTed to me from a
>'foreach' clause. Now, possibly in this foreach clause I want to register
>these name/value pairs into a session var. I have tried :
>session_start();
>foreach ($HTTP_POST_VARS as $name=>$value) {
>$name=$value;
>session_register(name); //without the $
>}
>and get nothing.
Assuming register_globals is off:
session_start();
foreach ($HTTP_POST_VARS as $name => $value) {
$$name = $value;
session_register($name);
}
Remember, $name only contains the name of the variable, not a
reference to the variable itself. To create a new global variable
with the name "$name", you have to use a variable variable, hence
$$name.
Session_register, however, only requires a string which contains the
name of the variable you want to register. $name will provide that by
itself. In your example, by leaving off the dollar sign, you are
referencing an undefined constant called "name"...