0

Is there any way to name a variable after another variable, I sort of made up this bit of code which I thought might work but it didn't

<php
$V_Name = 'variable';
$"$V_Name" = 'Hello';
print($variable);
?>

Bit of a long shot I know but I thought it might work,
Any other ideas, I wondered if there was a command like setvariable(); where you could set the variable name as a string but I couldnt find anything.
Regards,
Sam Rudge

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by samarudge
0

You can use something called a variable variable(yeah, I know it's weird)

$variable="name";
$$variable = "Shawn";
echo $name; // prints Shawn
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.