0
我正在寻找一个函数在教条中将空值转换为指定的默认值。所以ISNULL(A,B)应该返回B如果A空,A otherwice。有学说这样的功能?有没有ISNULL或学说IFNULL函数?
我正在寻找一个函数在教条中将空值转换为指定的默认值。所以ISNULL(A,B)应该返回B如果A空,A otherwice。有学说这样的功能?有没有ISNULL或学说IFNULL函数?
如果你正在谈论的对象抓空值,在实体写一个方法
<?php
// Entities/SomeEntity.php
class Foo
{
private $a;
private $b;
// ...
// Your getters and setters are here
// ...
public function myNullFunction()
{
if($this->a === null AND $this->b !== null)
{
return $this->b;
}
elseif($this->b === null && $this->a !== null)
{
return $this->a;
}
else
{
// ... Do something if both are null
}
}
}
然后,您可以使用此功能时,你已加载的对象(S)
$foo = $some_repository->getFooObject();
// The function returning a value that is a or b
$bar = $foo->myNullFunction();
你为什么不自己写呢? – Mansuro