In PHP, if I want to destroy variables and store them, the standard way to write them is to use the unset() function directly. However, our test will find that unset only occurs when all variables pointing to the value (such as reference variables pointing to the value) are The address will not be released until it is destroyed. Let's look at a few examples below.
First let’s look at an example:
The code is as follows
代码如下 |
复制代码 |
$a = "hello springload";
$b = $a;
unset($b);
echo $a; //hello springload
?>
|
|
Copy code
|
代码如下 |
复制代码 |
$a = "hello springload";
$b = $a;
unset($a);
echo $b;//hello springload
?>
|
$a = "hello springload";
$b = $a;
unset($b);
echo $a; //hello springload
?>
代码如下 |
复制代码 |
$a = "hello springload";
$b = $a;
unset($a);
unset($b);
echo $b;//输出空
?>
|
We know this very well, unset($b) only disconnects the variable name and value binding, but an interesting question arises: |
The code is as follows |
Copy code |
$a = "hello springload";
$b = $a;
unset($a);
echo $b;//hello springload
?>
Why is $a destroyed, and why is the value of $b still there?
Note: The unset() function will only release the address when all variables pointing to the value (such as reference variables pointing to the value) are destroyed, as follows:
The code is as follows
|
Copy code
|
$a = "hello springload";
$b = $a;
unset($a);
unset($b);
echo $b;//output empty
?>
http://www.bkjia.com/PHPjc/632674.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632674.htmlTechArticleIn php, if I want to destroy variables and memory release the standard way to write them is to use the unset() function directly, but we The test will find that unset is only used when all variables pointing to the value (such as reference variables...
|
|