+ 2

Tripple dollar. Please explain me, step by step, what does interpreeter do here and why it outputs dollardollar?

code: $dollar = "dollar"; $dollar = $dollar."dollar"; $dollardollar = $dollar; echo $$dollar;

12th Aug 2018, 12:22 PM
lock
5 Answers
+ 4
(I'm not sure if that kind of imaginary parentheses helps, but I'hope that such verbal step by step explanation is clear anyway... you just have to "parse and evaluate" those multiple "
quot; yourself like interpreter does.)
18th Aug 2018, 8:53 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 2
This is pretty self explanatory as it creates two strings of dollar joins them and the result is dollardollar
12th Aug 2018, 3:28 PM
BroFar
BroFar - avatar
+ 2
1st line: $dollar is equal to dollar. 2nd: see $dollar as $($dollar), now put a value of $dollar instead of $dollar and you'll get $(dollar), now drop those parentheses; now, $dollar equals concatenated $dollar (it's value, which is "dollar") and string literal "dollar". (So, now $dollar equals "dollardollar"). 3rd: a new variable comes here, it's $dollardollar and it equals "dollardollar" too. 4th: You can imagine some parentheses here again for those variable variables. $($($dollar)). So, evaluate "first" "expression" here (inside parentheses). $dollar equals "dollardollar" and now we have $($(dollardollar)). Drop the pair of parentheses as we have already evaluated "expression" inside... $($dollardollar). Evaluate again. $dollardollar equals "dollardollar" so we have $(dollardollar). Drop the last pair of parentheses and you'll have last and long waited variable here: $dollardollar which value is "dollardollar" and echo $dollardollar outputs "dollardollar".
18th Aug 2018, 8:48 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 1
BroFarOps Please help this guy...!
12th Aug 2018, 1:08 PM
Joshua Raison
Joshua Raison - avatar
+ 1
Hi. I manage to solve it out few days ago with my friend who works in IT and forgot about this question topic. However this explanation is exactly what I requested for. Thank you much for your effort. Take care. Greets.
18th Aug 2018, 9:31 PM
lock