Dev Expert Dev Expert - 5 months ago 14
PHP Question

PHP ${$?} Could someone shed some light?

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.

Answer

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).