0

Is there a way to return a variable variable from a function?

This is what I tried:

function varvar($num){
    $var = "foo".$num;
    return $$var;
}
varvar(3);
echo $foo3;

But nothing prints out. Any ideas?

1 Answer 1

2

You need to capture the return value in a variable:

function varvar($num){
    $var = "foo".$num;
    return $$var;
}
$foo3 = varvar(3);
echo $foo3;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.