Void
Unset (Mixed $ VaR [, Mixed $ VaR [, $... ])
Unset ()Destroys the specified variable. Note that in PHP 3,Unset ()ReturnsTrue(Actually an integer value of 1), while in PHP 4,Unset ()It is no longer a real function: it is now a statement. In this way, no return value is returned and an attempt is made to obtainUnset ()Will cause parsing errors.
Example #1Unset ()Example
// destroy a single variable
unset ( $ Foo );
// destroy a single array element
unset ( $ bar [ 'quux ' ]);
// Destroy more than one variable
Unset ($ Foo1,$ Foo2,$ Foo3);
?>
Unset ()The behavior in a function varies depending on the type of the variable to be destroyed.
IfUnset ()A global variable is destroyed, while the variables in the call environment will keep callingUnset ()The same value.
<? PHP
FunctionDestroy_foo(){
Global$ Foo;
Unset ($ Foo);
}
$ Foo='Bar';
Destroy_foo();
Echo$ Foo;
?>
The above example will output:
Bar
IfUnset ()A variable passed through the reference is only the local variable is destroyed, and the variable in the call environment will remain calledUnset ()The same value.
<? PHP
Function Foo (& $ Bar ){
Unset ( $ Bar );
$ Bar = "Blah" ;
}$ Bar='Something';
Echo"$ Bar\ N";
Foo($ Bar);
Echo"$ Bar\ N";
?>
The above example will output:
Something something
If unset () is a static variable in the function, the static variable is destroyed within the function. However, when this function is called again, the static variable is restored to the value before the previous destruction.
function Foo () {
static $ A ;< br> $ A +++;
echo " $ A \ n" ;< br> unset ( a A );
}< P>
Foo();
Foo();
Foo();
?>
The above example will output:
1 2 3
If you wantUnset ()A global variable that can be used$ GlobalsArray:
function Foo () {
unset ( $ globals [ 'bar' ]);
}< P>
$ Bar="Something";
Foo();
?>
Note: It is a language constructor rather than a function and cannot be called by variable functions.