It look's more complicated then it is. The key to it is the variable $var
I will try to explane each line by it self
$name1 = "Fredrik";
initiates $name1 to Fredrik
$name2 = "Andreas";
initiates $name2 to Andreas
$var = "name1";
initiates $var to name1
echo $var . " = " . ${$var};
this will print :
name1 = Fredrik
take a look at ${$var}, that code means:
the variable with the name in variable $var
therefore
${$var} equels the variable $name1
echo "<br>";
prints "<br>"
$var = "name2";
set $var to name2
echo $var . " = " . ${$var};
name1 = Andreas
now the variable $var conatins name2
therefore
${$var} equels the variable $name2
echo "<br>";
prints "<br>"
Hoppes this makes it a little clearer.