PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Citizen
Forum Contributor
Posts: 300 Joined: Wed Jul 20, 2005 10:23 am
Post
by Citizen » Thu Dec 28, 2006 9:55 am
I know this is a newbie question and I've tried a billion searches but....
How can I dynamically set a variable name?
For instance...
Code: Select all
$gg = "foo";
$gg.1 = "bar";
$echo "$gg1";
How can I rename variables?
dibyendrah
Forum Contributor
Posts: 491 Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:
Post
by dibyendrah » Thu Dec 28, 2006 10:35 am
$gg = "foo";
$$gg = "bar"
print $foo;
Output:
Are you looking for this ?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Dec 28, 2006 11:02 am
Code: Select all
$one = "one";
${$one . "two"} = "onetwo";
echo $onetwo;
And more to be found in the manual (section about variable variables)
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Thu Dec 28, 2006 12:45 pm
timvw wrote: Code: Select all
$one = "one";
${$one . "two"} = "onetwo";
echo $onetwo;
That's a neat thing, I'm going to use that!
I use variable variable names a lot.