note 63586 added to language.variables
| From: | jimmygoon at gmail dot com | Date: | Fri, 24 Mar 2006 16:03:26 +0000 |
| Subject: | note 63586 added to language.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106533@lists.php.net to get a copy of this message | ||
I had an application for this a while back and couldn't find a solution and ended up spending a
while testing things myself until I found a solution.
I'm adding this for Google's sake so that others can find it. I searched for: dynamic
variables, using contents of variable as variable name, declaring variables as variable names, etc.
So here's what I got:
<?php
$foo = "bar";
${$foo} = "goo";
echo $bar;
?>
This example set the variable $foo to "bar"... then declares a new variable from the
contents of $foo and sets its value to "goo"... effectively that line translates to $bar =
"goo". then I output the value of $bar just to prove the point and its works as assumed...
it prints "goo"...
Hope that helps someone else out!
----
Server IP: 64.71.164.2
Probable Submitter: 69.29.51.66
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.variables.php
Edit -- http://master.php.net/note/edit/63586
Del: integrated -- http://master.php.net/note/delete/63586/integrated
Del: useless -- http://master.php.net/note/delete/63586/useless
Del: bad code -- http://master.php.net/note/delete/63586/bad+code
Del: spam -- http://master.php.net/note/delete/63586/spam
Del: non-english -- http://master.php.net/note/delete/63586/non-english
Del: in docs -- http://master.php.net/note/delete/63586/in+docs
Del: other reasons-- http://master.php.net/note/delete/63586
Reject -- http://master.php.net/note/reject/63586
Search -- http://master.php.net/manage/user-notes.php