Page 1 of 1

Question about adding $i to the end of $variable

Posted: Mon Jan 09, 2006 4:25 pm
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

Posted: Mon Jan 09, 2006 5:01 pm
by timvw
Search the web for variable variables...

Code: Select all

$i = 10;
$teller10 = 100;
echo ${'teller' . $i};

Posted: Mon Jan 09, 2006 5:12 pm
by mikebr
At least I was on the right lines with the {}!

Thanks

Posted: Mon Jan 09, 2006 10:24 pm
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.

Posted: Tue Jan 10, 2006 5:55 am
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:

Posted: Tue Jan 10, 2006 6:30 am
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.