unset
unset
unset a given variable
void **unset** mixed $var mixed $vars
destroys the specified variables.
unset
The behavior of inside of a function
can vary depending on what type of variable you are attempting to
destroy.
unset
If a globalized variable is inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before was called.
unset``unset**Voorbeeld: Using **
<?php
function destroy_foo()
{
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>
To a global variable inside of a function, then use the array to do so:
unset``$GLOBALSVoorbeeld: a Global Variable
<?php
function foo()
{
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
?>
If a variable that is PASSED BY REFERENCE is inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before was called.
unset``unsetVoorbeeld: with Reference
<?php
function foo(&$bar)
{
unset($bar);
$bar = "blah";
}
$bar = 'something';
echo "$bar\n";
foo($bar);
echo "$bar\n";
?>
If a static variable is inside of a function, destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable.
unset``unsetVoorbeeld: with Static Variable
<?php
function foo()
{
static $bar;
$bar++;
echo "Before unset: $bar, ";
unset($bar);
$bar = 23;
echo "after unset: $bar\n";
}
foo();
foo();
foo();
?>
varThe variable to be unset.
varsFurther variables.
return.void
Voorbeeld: example
<?php
// destroy a single variable
unset($foo);
// destroy a single element of an array
unset($bar['quux']);
// destroy more than one variable
unset($foo1, $foo2, $foo3);
?>
Opmerking: > It is possible to unset object properties visible in the current context.
If declared, is called when accessing an unset property, and is called when setting an unset property.__get()__set()
Opmerking: > It is not possible to unset inside an object method.
$this
Opmerking: > When using on inaccessible object properties, the overloading method will be called, if declared.
unset__unset()
isset``empty__unset()array_splice(unset) casting