復制代碼 代碼如下:
< ?PHP
function destroy_foo() {
global $foo;
unset($foo);
}
$foo = ‘bar';
destroy_foo();
echo $foo;
?>
復制代碼 代碼如下:
< ?PHP
function foo() {
unset($GLOBALS['bar']);
}
$bar = “something”;
foo();
var_dump($bar);
?>
復制代碼 代碼如下:
< ?php
$test=str_repeat("1",256); //重復一個字符串,返回值為重復后組成的字符串
$s = memory_get_usage();
//該函數用來查看當前所用內存
unset($test);
$e = memory_get_usage();
echo ' 釋放內存: '.($s-$e);
//輸出為272,但如果上面test變量改為$test=str_repeat("1",255),輸出則為0 ,變量值不足256不會釋放內存的
?>
復制代碼 代碼如下:
< ?php
$test = str_repeat("1",256);
$p = &$test;
unset($test);
echo $p;
//輸出為256個1。如果上面改為unset($p),更不行了,echo $test 直接顯示為256個1
?>
復制代碼 代碼如下:
< ?php
$test = str_repeat("1",256);
$p = &$test;
$s = memory_get_usage();
$test = null;
unset($test); //試一下將該句與$test=null 調換先后順序,則結果將不相同
$e = memory_get_usage();
echo ' 釋放內存: '.($s-$e);
//輸出為272
var_dump($p); //輸出為NULL
?>
復制代碼 代碼如下:
< ?php
$test = str_repeat("1",256);
$p = &$test;
$s = memory_get_usage();
//注意,以下2個unset()順序對調沒有關系,不影響結果
unset($p);
unset($test);
$e = memory_get_usage();
echo ' 釋放內存: '.($s-$e); //輸出為272
?>
新聞熱點
疑難解答