Questions about variable reference $ foo = 'Bob ';
$ Bar = & $ foo;
$ Bar = "my name is $ bar ";
Echo $ bar .'
';
Echo $ foo;
This is an example in the manual. I have doubts that I can understand the result of outputting $ bar, but why is his value not Bob but my name is Bob when outputting $ foo, why does the value change? please explain it. thank you!
Reply to discussion (solution)
This is the difference between value assignment and reference.
$ Foo = 'Bob ';
$ Bar = & $ foo; // $ bar and $ foo point to the same variable table item.
Therefore, any change to $ bar will cause $ foo changes (except deletion)
Just like a person with two names
This is the difference between value assignment and reference.
$ Foo = 'Bob ';
$ Bar = & $ foo; // $ bar and $ foo point to the same variable table item.
Therefore, any change to $ bar will cause $ foo changes (except deletion)
Just like a person with two names
That is, once referenced, both variables are the same, right?
Yes. the values of both variables are the same.
Yes. the values of both variables are the same.
Thank you!