Php variable-php Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.