我有一个函数,我正在尝试将 NULL 值传递给:
function test($this=null, $that=null) {
if ($this) {
// Do something
}
if ($that) {
// Do something else
}
}
因此,如果我尝试仅为$that
传递一个值,我可以执行以下操作:
$that = 100;
this('',$that);
但是''
是将 NULL 传递给函数的最佳方式吗?
使用 null
:
$that = 100;
test(null,$that);
> 将null
值传递给 PHP 函数的最佳方法如下:
someFunction(null);
然后,要检查null
是否在函数内部传递,请使用 $param === null
或 is_null($param)
。
您需要找到空字符串和 null 之间的区别。这是不一样的。
最好的方法是使用
test(null, $that);
如果您使用===
运算符,您将看到差异