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

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

WBOY
Release: 2016-06-13 12:12:04
Original
1083 people have browsed it

第一种方法:$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('
Copy after login
');
?>

结果:

复制代码 代码如下:


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

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template