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