mizhko
mizhko

Reputation: 37

Changing variable into actual variable

Wanted to turn value of variable into variable itself. I am not getting result as expected.

The code, I am getting PHP parse error as syntax error, unexpected '{' on the isset line.

$Firstname="Andy";
$item="Firstname";
if(isset(${$item})))
{  echo ${$item};
}

I would have expected output of ${$item} would be "Andy"

The code, I am getting PHP parse error as syntax error, unexpected '{' on the isset line.

Upvotes: 0

Views: 26

Answers (1)

Manzurul Hoque Rumi
Manzurul Hoque Rumi

Reputation: 3094

You have syntax error. You have extra closing bracket ) Replace your code with the below code

$Firstname="Andy";
$item="Firstname";
if(isset(${$item}))
{  
     echo ${$item};
}

Upvotes: 1

Related Questions