note 45643 added to function.eval
| From: | mmrtnt at earthlink dot net | Date: | Mon, 13 Sep 2004 20:36:17 +0000 |
| Subject: | note 45643 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76641@lists.php.net to get a copy of this message | ||
Just searching the documentation for $$ doesn't appear to return any valid results. I think
this use of the operator is very similar to some of the uses of eval(), so I'm going to mention
it here. If there's some fundamental reason why this is bad, I would really appreciate it if
someone would let me know.
Instantiating variables on the fly can be really useful. I'm sure there are better ways to get
a form's values as PHP vars, but this example is used just to illustrate how the $$ operator
works.
Given:
<form>
<input type="text" name="name" value="">
<input type="text" name="email" value="">
<input type="text" name="phone" value="">
</form>
You can then do this:
<?php
foreach( $_POST as $key => $value )
{
$$key = $value;
}
?>
This will give you $name, $email and $phone with the values inputted by the user.
MjM
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45643
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45643&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45643&report=yes
Search -- http://master.php.net/manage/user-notes.php