sisko sisko - 1 year ago 121
PHP Question

PHP double $ meaning

I inherited some legacy code where I found the following typo:

foreach ($$node_list as $e) {

I assumed the
was wrong and removed one but the code did not function as it once did.

Thankfully, I began comparing my code updates to the original, spotted my change as described above and replaced the extra dollar symbol - just to see it it made the difference.

To my surprise, it did make the difference and the code functioned correctly as it once did.

Can anyone please explain what
means in PHP?

Answer Source

It's called a variable variable

As an example:

$a = 'hello'; // creates variable $a with value "hello"
$$a = 'world'; // creates variable $hello with value "world"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download