Variable names

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

Post Reply
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Variable names

Post by Citizen »

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?
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

$gg = "foo";
$$gg = "bar"

print $foo;

Output:

Code: Select all

bar
Are you looking for this ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

$one = "one";
${$one . "two"} = "onetwo";
echo $onetwo;
And more to be found in the manual (section about variable variables)
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

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.
Post Reply