Joe
Joe

Reputation: 610

Making a variable out of another variables' value in php (php basics)

I need to make a dynamic variable based on a loop, what i am looking for is a variable something like

$var = "foo";

$$var = "bar";

echo $foo; // bar

but for me it should be more like a fixed parameter attached to the dynamic part like

$var='123';

$'current_'.$$var=some value; // not correct syntax

echo $current_123 should give 'some value';

Upvotes: 0

Views: 62

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163238

Use curly braces:

$${'current_' . $var} = $some_value;

Upvotes: 3

Related Questions