©
本文档使用
php.cn手册 发布
当 unset 一个引用,只是断开了变量名和变量内容之间的绑定。这并不意味着变量内容被销毁了。例如:
<?php
$a = 1 ;
$b =& $a ;
unset( $a );
?>
再拿这个和 Unix 的 unlink 调用来类比一下可能有助于理解。
[#1] ojars26 at NOSPAM dot inbox dot lv [2008-05-03 07:41:22]
Simple look how PHP Reference works
<?php
$a=10;
$b=20;
$c=array ('one'=>array (1, 2, 3));
$a=&$c['one'][2];
$b=&$a; // or $b=&$c['one'][2]; result is same as both "$c['one'][2]" and "$a" is at same pointer.
unset($c['one'][2]);
$c['one'][2]=500; //now it is in array
$c['one'][2]=&$a;
unset($a);
unset($b);
echo $foo; // output : hello I am Frank
echo $bar; // output : due!
?>
[#5] libi [2006-01-24 00:20:32]
clerca at inp-net dot eu dot org
"
If you have a lot of references linked to the same contents, maybe it could be useful to do this :
<?php
$a = 1;
$b = & $a;
$c = & $b; // $a, $b, $c reference the same content '1'
$b = NULL; // All variables $a, $b or $c are unset
?>
"
------------------------
NULL will not result in unseting the variables.
Its only change the value to "null" for all the variables.
becouse they all points to the same "part" in the memory.