0
$var="profile['Gamer']['last_name']";
echo ${$var};

Gives

Undefined variable: profile['Gamer']['last_name']

. But if i try to echo $profile['Gamer']['last_name'] value exist

I have tried echo $$var that too didn't work

3
  • Specifying an array index using curly braces isn't possible. Commented Mar 21, 2011 at 13:42
  • Why are you trying to do this? What's wrong with echo $profile['Gamer']['last_name']; Commented Mar 21, 2011 at 13:43
  • 2
    Only ${"profile"}['Gamer']['last_name'] will work. Commented Mar 21, 2011 at 13:43

3 Answers 3

4

There is no variable profile['Gamer']['last_name']. There is only a variable named profile.

$var = "profile";
echo ${$var}['Gamer']['last_name'];
Sign up to request clarification or add additional context in comments.

Comments

0
$var="profile['Gamer']['last_name']";
eval('$result = $' . $var . ';');
echo $result;

Keep in mind that there are serious security issues to something like this, and that your code will probably be very hard to understand for anybody but your self.

1 Comment

my aim is to check if user has filled in data for a database field. If filled i assign him some points. To do so in another table i store the fild name and the points associated with it. so what's the best way to implement. and what r the security issues . None one but i have acess to thsi table
0

try this:

$var="profile['Gamer']['last_name']";
eval("echo $".$var.";");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.