<?php
// 変数を一つ破棄する
unset ($foo);
// 配列の要素の一つを破棄する
unset ($bar['quux']);
// 複数の変数を破棄する
unset ($foo1, $foo2, $foo3);
?>
<?php
function destroy_foo()
{
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>
bar
<?php
function foo()
{
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
?>
<?php
function foo(&$bar)
{
unset($bar);
$bar = "blah";
}
$bar = 'something';
echo "$bar\n";
foo($bar);
echo "$bar\n";
?>
something
something
<?php
function foo()
{
static $bar;
$bar++;
echo "Before unset: $bar, ";
unset($bar);
$bar = 23;
echo "after unset: $bar\n";
}
foo();
foo();
foo();
?>
Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
固有名詞の分類