0
有兩種方式或更多我可以使該功能 一爲什麼是使用更多的回報和返回每次我不需要繼續功能和另一種方式是使用 更多ifs,否則ifs ,elses,PHP的編碼風格比較vs返回
function getCountOfWhatEverMethodType1
{
$return = false;
// ----
if($user->isLogged)
{
if(getDBOBlaBla->equal(1))
{
$return = 2;
}
else if(getDBOBlaBla->equal(2))
{
$return = 3;
}
else
{
$return = 1;
}
}
// ----
return $return;
}
function getCountOfWhatEverMethodType2
{
if(!$user->isLogged)
{
return false;
}
$return = 1;
// ----
if(getDBOBlaBla->equal(1))
{
$return = 2;
}
else if(getDBOBlaBla->equal(2))
{
$return = 3;
}
// ----
return $return;
}
一個我應該使用,爲什麼?
嘿感謝我更新了代碼之前我犯了一些錯誤 – user3301396
@ user3301396我已更新我的代碼然後 –
我看到,但我仍然不明白爲什麼是更好(如果它)使用2或1內的Type3 – user3301396