-2
What will be printed on the screen by this script
?
<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo};
?>
-2
What will be printed on the screen by this script
?
<?php
$foo = 'bar';
$bar = 'foo';
print ${$foo};
?>
2
In PHP a key following dollar can be the definition of a variable with strange names or its reading. What happens in the example is the value of $foo
and play at reading then turns ${bar}
containing the value foo
.
Related:
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 php script
You are not signed in. Login or sign up in order to post.
Is PHP that? script gets beeeem Generico.
– rray
Will be printed, I don’t even know what I’m talking about.
– Marco Souza
What is the utility of declaring variables through braces?
– rray