0

I'm touching up on some PHP that I sometimes forget (keep the old brain going) and came across this in a PHP questionnaire. It goes as follows:

<?php
$a = "b";
$b = "a";

print ${$b} ;
//$b = "b"
?>

How does this work and how would I use it practically? Thank you in advance.

PHP Noob
  • 413
  • 1
  • 6
  • 19

1 Answers1

1

This is a variable variable

print ${$b} 

It first evaluates {$b} and gets 'a'. So then it evaluates $a and gets "b" (the value stores in $a).

Dekel
  • 60,707
  • 10
  • 101
  • 129
dave
  • 62,300
  • 5
  • 72
  • 93