Php variable problem $ baaa; $ a & amp; $ B; $ bddd; unset ($ B); echo $ a; output ddd at this time; question: $ a & amp; $ B; this statement assigns the memory address of variable B to $ a. changing the value of value a of variable B also changes the value of unset ($ B) to destroy variable B; why can echo $ a still output values? ------ Solution -------------------- $ bd php variable problem
$ B = 'aaa ';
$ A = & $ B;
$ B = 'ddd ';
Unset ($ B );
Echo $;
Output ddd;
Question: $ a = & $ B; this statement assigns the memory address of variable B to $ a. changing the value of B a also changes.
Unset ($ B) destroys variable B. Why does echo $ a still output values?
------ Solution --------------------
$ B = 'ddd 'has changed the memory address of $ B.
------ Solution --------------------
$ A = & $ B first. In fact, $ a is implicitly directed to the address of $ B. after you unset ($ B), you only cancel the ing between $ B and the value, it does not affect $.
I wonder if the description is clear... Cold, it's not php for a long time, so it's getting worse in expression.
------ Solution --------------------
PHP code
// From the C perspective, the structure of $ a contains a pointer to the $ B variable, that is, $ a stores the address of the $ B variable, // after unset ($ B), the php engine does not actually release the content of this address, the release time of the variable should be determined by the engine's memory recycle mechanism $ B = 'aaa'; $ a = & $ B; $ c = & $ B; // A reference is added here. this may also be taken into account by the php engine, so the variable is not immediately released. // when there are too many memory fragments, the variable will be recycled and reused, avoid repeatedly applying for small memory blocks to reduce efficiency $ B = 'CC'; unset ($ B); $ c = 'ddd '; unset ($ c); echo' $ '. $ a; // output ddd // The above is just speculation, for reference only