What will be printed on the screen by this script
?
<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo};
?>
What will be printed on the screen by this script
?
<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo};
?>
In PHP a braces following code can be the definition of a variable with strange names or its reading. What happens in the example is the value of $foo
and game in reading then it turns ${bar}
that contains the value foo
.
Related:
By logic, the printed value is bar, but because this value was assigned the variable $ foo.
Edit: Yes, testing on Fiddle, it prints foo, but I did not understand why ...