aWebDeveloper
aWebDeveloper

Reputation: 38402

variable in variable in php

$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

Upvotes: 0

Views: 132

Answers (3)

Michael S.
Michael S.

Reputation: 1

try this:

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

Upvotes: 0

troelskn
troelskn

Reputation: 117615

$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.

Upvotes: 0

Marcel Jackwerth
Marcel Jackwerth

Reputation: 54782

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

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

Upvotes: 4

Related Questions