Home  >  Article  >  Backend Development  >  How to eliminate variables in php

How to eliminate variables in php

藏色散人
藏色散人Original
2021-05-10 10:13:362324browse

In PHP, variables can be eliminated through the unset function. The syntax is such as "unset(mixed $var, mixed $...=?):void", where the parameter var represents the variable to be destroyed.

How to eliminate variables in php

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

unset

(PHP 4, PHP 5, PHP 7, PHP 8)

unset — Release the given variable

Description

unset ( mixed $var , mixed $... = ? ) : void

unset( ) destroys the specified variable.

The behavior of unset() in a function will vary depending on the type of variable you want to destroy.

If you unset() a global variable in a function, only the local variable will be destroyed, and the variables in the calling environment will maintain the same value before calling unset().

The above routine will output:

bar

If you want to unset() a global variable in the function, you can use the $GLOBALS array to achieve this:

If in If a variable passed by reference is unset() in the function, only the local variable will be destroyed, and the variables in the calling environment will maintain the same value before calling unset().

The above routine will output:

something
something

If a static variable is unset() in a function, the static variable will be destroyed inside the function. However, when this function is called again, this static variable will be restored to the value it had before it was last destroyed.

The above routine will output:

Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23

Parameters

var

The variable to be destroyed.

...

Other variables...

Return value

No return value.

Example

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to eliminate variables in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn