|
<?php
$long="big_long_variable_name";
$$long="php"; /* 用存放在變量$long里的字符串作為新變量的變量名,等同于$big_long_variable_name="php"; */
$short=& $big_long_variable_name; /* 取變量$big_long_variable_name的值賦給變量$short,此時$short的值為"php",等同于$short=& $$long; */
print "01 /$short is $short."; /* "/$"是轉義序列,表示輸出一個美元符號$,下同。本語句的作用是輸出:01 $short is php. */
print "02 Long is $big_long_variable_name."; /* 輸出:02 Long is php. */
?>
<br />
<br />
<?php $big_long_variable_name.=" rocks!"; /* 重新對$big_long_variable_name賦值。重新賦值過程中,由于在$big_long_variable_name的后面添加了.(點號),因而變量$big_long_variable_name此時的值應為原值("php")+新值(" rocks!"),即變量$big_long_variable_name當前完整的值為"php rocks!"。下同。*/
print "03 /$short is $short"; /* 輸出:03 $short is php rocks! */
print "04 Long is $big_long_variable_name"; /* 輸出:04 Long is php rocks! */
?>
<br />
<br />
05 $short is php rocks!
06 Long is php rocks!
<br />
<br />
<?php $short.="Programming $short"; /* 重新對變量$short賦值。由于在$short后面添加了.(點號),因此請參考上例分析$short的值。*/
print "07 /$short is $short"; /* 輸出:07 $short is php rocks!Programming php rocks! */
print "08 Long is $big_long_variable_name"; /* 由于變量$short被重新賦值為Programming php rocks!,因而變量$big_long_variable_name的值也與$short一同被改變為"php rocks!Programming php rocks!"。本語句輸出:08 Long is php rocks!Programming php rocks!注意,如果是對具有相同值的一個變量進行銷毀unset( ),則另一個變量不適用于此種情況,即不會隨之被一同銷毀。*/
?>
<br />
<br />
09 $short is Programming php rocks!
10 Long is Programming php rocks!
<br />
<br />
<?php $big_long_variable_name.="Web Programming $short"; /* 變量$big_long_variable_name被重新賦值,此時它完整的值應為php rocks!Programming php rocks!Web Programming php rocks!Programming php rocks!。變量$short的值此時與變量$big_long_variable_name一致。請分別參考第5處、第10處注釋進行分析。*/
print "11 /$short is $short"; /* 輸出: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); /* 用unset( )銷毀變量$big_long_variable_name,變量$short不會因此受到任何影響。*/
print "13 /$short is $short"; /* 雖然銷毀了變量$big_long_variable_name,但$short沒有受到影響,它的值仍是最近一次被賦予的php rocks!Programming php rocks!Web Programming php rocks!Programming php rocks! */
print "14 Long is $big_long_variable_name."; /* 變量$big_long_variable_name已被銷毀,故而無值。輸出:14 Long is. */
snow;
?>
<br />
<br />
<?php $short="No point TEST1"; /* 重新對變量$short賦值。由于這次沒有在$short后面添加.(點號),因此$short當前的值為"No point TEST1"。*/
print "15 /$short is $short."; /* 輸出:15 $short is No point TEST1. */
$short="No point TEST2 $short"; /* 重新對變量$short賦值。沒在$short的后面添加.(點號),但引用了它自身最近一次的值"No point TEST1"。*/
print "16 /$short is $short."; /* 輸出:16 $short is No point TEST2 No point TEST1. */
php技術:PHP變量的定義、可變變量、變量引用、銷毀方法,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。