Home >Backend Development >PHP Tutorial >PHP中删除变量时unset()和null的区别分析_php技巧

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-17 09:21:29787browse

第一种方法:$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