note 63586 deleted from language.variables by bjori

From: Date: Thu, 20 Apr 2006 18:36:02 +0000
Subject: note 63586 deleted from language.variables by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108847@lists.php.net to get a copy of this message
Note Submitter: jimmygoon at gmail dot com ---- 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!

« previous php.notes (#108847) next »