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

Alanni ·
更新时间:2024-09-21
· 803 次阅读

第一种方法:$varname=null
第二种方法:unset($varname)
这两种方法都可以删除变量,但结果有些许的差别。
代码:
代码如下:
<?php
$a = array(
'a' => 'a',
'b' => 'b'
);
$b = array(
'a' => 'a',
'b' => 'b'
);
$a['b'] = null;
unset($b['b']);
print('<pre>');
print_r($a);
print('<br />');
print_r($b);
print('</pre>');
?>

结果:
代码如下:
Array
(
[a] => a
[b] =>
)
Array
(
[a] => a
)
您可能感兴趣的文章:PHP中检查isset()和!empty()函数的必要性PHP isset()与empty()的使用区别详解php reset() 函数指针指向数组中的第一个元素并输出实例代码Python 检查数组元素是否存在类似PHP isset()方法PHP中isset()和unset()函数的用法小结PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法PHP中__set()实例用法和基础讲解



unset null PHP 变量

需要 登录 后方可回复, 如果你还没有账号请 注册新账号