What will be printed on the screen by this script?

Asked

Viewed 342 times

-2

What will be printed on the screen by this script ?

<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo}; 
?>

2 answers

2


  • I save my life, thank you :D

  • @Carolinewitts, if you want you can create a variable like this ${0} = 'wow'; echo ${0};

-1

Logically, the printed value is bar, but because this value was assigned to the variable $foo.

Edit: Yes, testing in Fiddle, it is printed foo, but I did not understand why...

  • No no no, it will print foo.

  • Oh guys, I’m lost now

  • It is php so the result is not bar. hahaha :D

  • @There are Fiddle’s for several languages, including PHP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.