Definition of PHP variable variable variable variable reference destruction method

  • 2020-11-30 08:11:52
  • OfStack


<?php
$long="big_long_variable_name";
$$long="PHP";     /*  Store variables with $long String as the variable name of the new variable, equal to $big_long_variable_name="PHP"; */
$short=& $big_long_variable_name;  /*  Take a variable $big_long_variable_name Is assigned to the variable $short At this time, $short The value of "PHP" Is the same as $short=& $$long; */
print "01 /$short is $short.";   /* "/$" Is an escape sequence that represents the output 1 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!"; /*  Back to the $big_long_variable_name The assignment. During the reassignment process, as in $big_long_variable_name It's added at the end of . (dot), hence the variable $big_long_variable_name At this point, the value should be the original value ( "PHP" ) + The new value ( " rocks!" ), i.e., variable $big_long_variable_name The current full value 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";   /*  Repair variables $short The assignment. Due to the $short And then we add . (dot), so please refer to the analysis above $short The value of the. */
print "07 /$short is $short";   /*  Output: 07 $short is PHP rocks!Programming PHP rocks! */
print "08 Long is $big_long_variable_name"; /*  Due to the variable $short Is re-assigned to Programming PHP rocks! , thus the variable $big_long_variable_name Also with the value $short1 Be changed to be "PHP rocks!Programming PHP rocks!" . Output of this statement: 08 Long is PHP rocks!Programming PHP rocks! Notice, if it's a pair that has the same value 1 Five variables were destroyed unset( ) , the other 1 The variables are not applicable in this case, i.e., will not be followed by 1 With the destruction. */
?>
<br />
<br />
09 $short is Programming PHP rocks!
10 Long is Programming PHP rocks!
<br />
<br />
<?php $big_long_variable_name.="Web Programming $short";  /*  variable $big_long_variable_name Is re-assigned, in which case its full value should be PHP rocks!Programming PHP rocks!Web Programming PHP rocks!Programming PHP rocks! . variable $short With variables $big_long_variable_name1 Cause. Please refer to the Numbers respectively 5 And the first 10 Comment for analysis. */
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);   /*  with unset( ) Destruction of a variable $big_long_variable_name , the variable $short It won't affect me in any way. */
print "13 /$short is $short";   /*  Although the variable is destroyed $big_long_variable_name , but $short It has not been affected and its value is still recent 1 Secondary endowed PHP rocks!Programming PHP rocks!Web Programming PHP rocks!Programming PHP rocks! */
print "14 Long is $big_long_variable_name."; /*  variable $big_long_variable_name It has been destroyed and therefore has no value. Output: 14 Long is. */
snow;                                    
?>
<br />
<br />
<?php $short="No point TEST1";   /*  Repair variables $short The assignment. Not this time $short The back to add . (dot), so $short The current value is "No point TEST1" . */
print "15 /$short is $short.";   /*  Output: 15 $short is No point TEST1. */
$short="No point TEST2 $short";   /*  Repair variables $short The assignment. Not in $short To the end of . (dot), but refers to itself as the nearest 1 The value of the time "No point TEST1" . */
print "16 /$short is $short.";   /*  Output: 16 $short is No point TEST2 No point TEST1. */

Related articles: