PHP variable definition, variable, variable reference, and destruction method

Source: Internet
Author: User

PHP variable definition, variable, variable reference, and destruction method

This article mainly introduces the definition of PHP variables, variable variables, variable references, and destruction methods. For more information, see

The Code is as follows:

<? Php

$ Long = "big_long_variable_name ";

$ Long = "PHP";/* use the string stored in the variable $ long as the name of the new variable, equivalent to $ big_long_variable_name = "PHP ";*/

$ Short = & $ big_long_variable_name;/* assign the value of $ big_long_variable_name to the variable $ short. The value of $ short is "PHP ", equivalent to $ short = & $ long ;*/

Print "01/$ short is $ short.";/* "/$" is an escape sequence, indicating to output a dollar sign $, the same below. The purpose of this statement is to output: 01 $ short is PHP .*/

Print "02 Long is $ big_long_variable_name.";/* output: 02 Long is PHP .*/

?>

<Br/>

<Br/>

<? Php $ big_long_variable_name. = "rocks! ";/* Assign a value to $ big_long_variable_name again. During the value re-assignment process, because the. (point number) is added after $ big_long_variable_name, the value of the variable $ big_long_variable_name should be the original value ("PHP") + new value ("rocks! "), That is, the current complete value of the variable $ big_long_variable_name is" PHP rocks! ". The same below. */

Print "03/$ short is $ short";/* output: 03 $ short is PHP rocks! */

Print "04 Long is $ big_long_variable_name";/* output: 04 Long is PHP rocks! */

?>

<Br/>

<Br/>

05 $ short is PHP rocks!

06 Long is PHP rocks!

<Br/>

<Br/>

<? Php $ short. = "Programming $ short";/* value the variable $ short again. Because. (DOT) is added to the end of $ short, please refer to the above example to analyze the value of $ short. */

Print "07/$ short is $ short";/* output: 07 $ short is PHP rocks! Programming PHP rocks! */

Print "08 Long is $ big_long_variable_name";/* The variable $ short is assigned a new value to Programming PHP rocks !, Therefore, the value of $ big_long_variable_name is changed to "PHP rocks!" together with $ short! Programming PHP rocks! ". Output of this statement: 08 Long is PHP rocks! Programming PHP rocks! Note: If you destroy unset () for a variable with the same value, the other variable is not applicable to this situation and will not be destroyed together. */

?>

<Br/>

<Br/>

09 $ short is Programming PHP rocks!

10 Long is Programming PHP rocks!

<Br/>

<Br/>

<? Php $ big_long_variable_name. = "Web Programming $ short";/* The variable $ big_long_variable_name is assigned a new value, and the complete value should be PHP rocks! Programming PHP rocks! Web Programming PHP rocks! Programming PHP rocks !. The value of $ short is consistent with $ big_long_variable_name. For analysis, see comments in section 5th and section 10th. */

Print "11/$ short is $ short";/* output: 11 PHP rocks! Programming PHP rocks! Web Programming PHP rocks! Programming PHP rocks! */

Print "12 Long is $ big_long_variable_name ";

?>

<Br/>

<Br/>

<? Php

Unset ($ big_long_variable_name);/* use unset () to destroy the variable $ big_long_variable_name. The variable $ short will not be affected. */

Print "13/$ short is $ short";/* although the variable $ big_long_variable_name is destroyed, $ short is not affected and its value is still the PHP rocks that was last granted! Programming PHP rocks! Web Programming PHP rocks! Programming PHP rocks! */

Print "14 Long is $ big_long_variable_name.";/* The variable $ big_long_variable_name has been destroyed and therefore has no value. Output: 14 Long is .*/

Snow;

?>

<Br/>

<Br/>

<? Php $ short = "No point TEST1";/* value the variable $ short again. Because No. is added after $ short this time, the current value of $ short is "No point TEST1 ". */

Print "15/$ short is $ short.";/* output: 15 $ short is No point TEST1 .*/

$ Short = "No point TEST2 $ short";/* value the variable $ short again. No. is added after $ short, but its last value "No point TEST1" is referenced ". */

Print "16/$ short is $ short.";/* output: 16 $ short is No point TEST2 No point TEST1 .*/

 

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.