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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-17 09:21:29
Original
793 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
)
Related labels:
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
Latest Issues
The unset() function is not explained.
From 1970-01-01 08:00:00
0
0
0
PHP array comparison unset problem
From 1970-01-01 08:00:00
0
0
0
About unset() within function
From 1970-01-01 08:00:00
0
0
0
functionunset()
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template