variable variables
<?php // if we want to output variable variables value we use in echo two dollars sign $$ for example $fruit = 'apple'; $apple = "apple is fruit"; echo $$fruit; // output will be "apple is fruit" ?>
by ana meskhi
2 years ago
PHP
php
variable
variables
1
Pro tip: use ```triple backticks around text``` to write in code fences
-1
Luka Khitaridze 2 years ago
// $fruit stores the value 'apple', so $$fruit will refer to the variable with name apple i.e., $apple.
REPLY
0
ana meskhi 2 years ago
Yes, This is a speed error
REPLY
1
ana meskhi 2 years ago
No Luka this was correct , this is variable variables and answer is correct. i check my note now and this was absolute correct . With PHP, you can use one variable to specify another variable's name. So, a variable variable treats the value of another variable as its name . <?php $a = 'hello'; $hello = "Hi!"; echo $$a; ?> Please write comments carefully in the future before you deslike someone note . Good luck
REPLY
Show 2 replies