Home >php教程 >php手册 >PHP中删除变量时unset()和null的区别分析

PHP中删除变量时unset()和null的区别分析

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:12:041086browse

第一种方法:$varname=null
第二种方法:unset($varname)
这两种方法都可以删除变量,但结果有些许的差别。
代码:

复制代码 代码如下:


$a = array(
'a' => 'a',
'b' => 'b'
);
$b = array(
'a' => 'a',
'b' => 'b'
);
$a['b'] = null;
unset($b['b']);
print('

'); <br>print_r($a); <br>print('<br>'); <br>print_r($b); <br>print('
');
?>

结果:

复制代码 代码如下:


Array
(
[a] => a
[b] =>
)
Array
(
[a] => a
)

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