-3
如果在PHP中使用if()函數時需要檢查多個語句/參數,那麼最佳實踐是什麼?PHP IF函數檢查多個語句/參數
例子:
if (isset($string) && empty($string2) {
code
}
或應該把它改爲:
if ((isset($string)) && (empty($sting2))) {
code
}
如果在PHP中使用if()函數時需要檢查多個語句/參數,那麼最佳實踐是什麼?PHP IF函數檢查多個語句/參數
例子:
if (isset($string) && empty($string2) {
code
}
或應該把它改爲:
if ((isset($string)) && (empty($sting2))) {
code
}
在你的榜樣,我不會用第二組括號。
if ((isset($string) || isset($strstr)) && empty($sting2)) {
code
}
無需額外的括號......我要離開出來:當條件的邏輯是一個比較複雜一點,比如,例如需要
額外的括號。但是,我傾向於在操作順序發揮作用時添加它們,只是爲了明確我想如何分組。 – Brad
無論哪種方式工作,我個人使用額外的括號來組織我的代碼,但更多 –