Value as variable name [solved]

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
KtRhN
Forum Newbie
Posts: 2
Joined: Sun Aug 13, 2006 6:51 pm

Value as variable name [solved]

Post by KtRhN »

I've ever asked myself if it's possible to use the value of an object as a variable name. Something like this:

Code: Select all

$test='abc';
$foo[$test] = 'bla'; // $foo['abc'] = 'bla'
but this doesn't work. is there a solution to solve that problem?
Last edited by KtRhN on Sun Aug 13, 2006 7:20 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How is that not working for you? This works all over the place in PHP.
KtRhN
Forum Newbie
Posts: 2
Joined: Sun Aug 13, 2006 6:51 pm

Post by KtRhN »

Thank you very much. I got "Illegal offset type" everytime due to an error of a much more complex statement and thought that that would be the reason. Now it works. :-)
Post Reply