phpdvpr Posted October 7, 2017 Share Posted October 7, 2017 Hi Larry, I was going through the end of chapter questions for Chapter 4. The second bullet point asks why the following code won't work? print "The total is $$total"; However when I run that code it does work, by which I mean it prints out "The total is 10" when $total = 10. I am running windows 10, PHP 7.1.9 Link to comment Share on other sites More sharing options...
Larry Posted October 14, 2017 Share Posted October 14, 2017 Sorry about the confusion! My expectation is this is due to a change in more recent versions of PHP. In older versions, it would have treated $$total as a "variable variable", but it looks like it's being smarter now. A variable variable would work like this: $cat = 'dog'; $dog = 42; print $$cat; // Prints 42 b/c it takes the value of $cat--"dog"--and inserts that to create "print $dog". Sorry about that! Link to comment Share on other sites More sharing options...
Recommended Posts