Question about adding $i to the end of $variable

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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Question about adding $i to the end of $variable

Post by mikebr »

I need to add $i to the end of $variable, for example:

$variable + $i to make $variable1, $variable2 etc.

$variable{$i} rings a bell but it doesn't seem to work,

anyone know if this is possible, and if so how?

Thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Search the web for variable variables...

Code: Select all

$i = 10;
$teller10 = 100;
echo ${'teller' . $i};
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

At least I was on the right lines with the {}!

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

for future reference, they are called variable variables.

what's really sad is I typed that url from memory. I haven't gone to that page in months.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

feyd wrote:what's really sad is I typed that url from memory. I haven't gone to that page in months.
Walking encyclopedia... :wink:
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

I think timvw was right.
most of the variables like that I use the way he said, it will be very easy to handle.
Post Reply