What will be printed on the screen by this script?

-2

What will be printed on the screen by this script ?

<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo}; 
?>
    
asked by anonymous 31.03.2016 / 20:42

2 answers

2

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 .

Example - ideone

Related:

What is the use of declaring variables using braces?

Special Characters in Identifiers

    
31.03.2016 / 20:53
-1

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

    
31.03.2016 / 20:49