+ 2

Variable variables

<?php $a = 'hello'; $hello = "Hi!"; echo $a; ?> // why does this print out Hi! And not the hello part

11th Apr 2018, 4:22 AM
sean
6 ответов
+ 4
Using two $ means getting the variable with the name of the text written in variable a It translate to: $a = $hello = ‘hi’
11th Apr 2018, 4:25 AM
Ariela
Ariela - avatar
+ 3
Well if you want to use a different variable depending on some circumstance, you can assign it later on the name to a string later on and reference it using two dollar signs
11th Apr 2018, 8:41 PM
Ariela
Ariela - avatar
+ 1
Still doesn’t really make since to me
11th Apr 2018, 4:27 AM
sean
0
Why assign a with hello
11th Apr 2018, 4:28 AM
sean
0
Why would you use so many $$ like you did on that code when you already determined the variables
11th Apr 2018, 2:23 PM
sean
- 1
Ohhh I understand now
11th Apr 2018, 4:29 AM
sean