PHP宏替换[关闭]

Consider this.

Var1= "Var2"
Var2= 100

I need to create a program that could act somewhat like this:

 Echo $Var1      (result: Var2)
 Echo ($Var1)    (result: 100)

Is it possible in PHP?

Variable variables:

echo $$Var1;

You can do some weird stuff in PHP:

$one = 'anythingHere321';
$two = 'anything';
$three = 'here';

$anythingHere321 = 'It Works!';

echo $$one, '<br>';
echo ${$one}, '<br>';
echo ${$two . ucfirst($three) . (300 + 21)}, '<br>';

Basically, you can put pretty much anything inside ${}, as long as it can be converted to a string. All these are valid:

${"string"};
${123};
${12.3};
${null};
${true};
${false};

Now, just because you can does not mean you should. You should use an array, or something like that, instead. Variable variables are more of a curiosity, or oddity, and not something you should use.

<?php
$Var1 = "Var2";
$Var2 = 100;
echo $$Var1;
// result output: "100"