Variable assignment and destruction

Source: Internet
Author: User
There are two types of variable assignment and destruction variable assignment: 1. Pass value assignment. First, see the figure below: where the variable name is stored, you can see it as an individual, and the value and type of the equipment are one by one, each variable name corresponds to a value and a hidden property (type). The name will not be affected. Similarly, changing your name will not affect others. This value assignment is called a value assignment. Code: $ A = 23; $ B = 20; $ B = $ A; var_dump ($ A, $ B); // code analysis: to print the variable $, $ B. Its value is ?? First, let's look at $ A. The value is 23. Then, we can see that $ B is a variable $ A. In that calculation, the value of $ A is 23, and then 23 is assigned to $ B. finally, the result is int 23 int23. (there is also a little bit of knowledge here to know that the Code executed in PHP is from top to bottom, step by step, until the last line. So, at the end of the execution, to print the variable $ B is to view the $ B = $ a line, rather than the previous line) $ B = "XX"; var_dump ($ A, $ B) // code analysis: $ A, or 23 $ B = 'xx'. This is a value assignment process. If the string is assigned to $ B, the value of $ B is 'xx, result: int 23 string 'xx' (lenght2) -- this is the string length. 2. The Reference Assignment of variable assignment is shown in the following code. Think about it. <? PHP $ li = 29; $ Wang = 23; $ Wang = & $ Li; var_dump ($ Li, $ Wang); // print the int 29 int 29 Code explanation: the & $ Li sentence is interpreted as assigning the $ il storage address to $ Wang directly, so that $ Li and $ Wang have a storage location. In this way, the output is 29 $ Wang = 'W'; var_dump ($ Li, $ Wang); // print string 'w' (length = 1) string 'w' (length = 1) code explanation: because a stored value address corresponds to two variables, the value of one variable is changed, and other values are also changed, therefore, the above results are printed. ?> 3. Destroy variables (unset) meaning: for large arrays, objects can be released in time <? PHP $ A = 100; unset ($ A); If (isset ($ A) {echo '$ A exists';} else {echo '$ A does not exist '; // does not exist}?> <? PHP $ li = 29; $ Wang = 23; $ Wang = & $ Li; unset ($ Li); var_dump ($ Wang, $ Li); // printed out, int 29 null. Think about why not all are null. If you understand, it means that the above knowledge has passed. ?> 4. Use the value of a dynamic variable as the name of another variable. <? PHP $ Lisi = 'man '; $ one = 'lisi'; $ Pi = 'one'; echo $ one, $ {$ one}, $ PI; // dynamic variable. Use the value of the variable as the name of another variable. Print Lisi man?>

Variable assignment and destruction

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.