2013-07-10 64 views
5

我一直使用這段代碼來運行一行if語句。

$variable = TRUE; // or anything that evaluates to TRUE 
$variable && execute_code(); 

基本上,如果$variable爲TRUE,它將運行該函數。我的問題: 這樣做的正確術語是什麼?

+0

me2,我在js中使用過,但在php中似乎不能很好地工作...... – Ziarno

+0

嗯,實際上它確實有效。至少在這種情況下。我的問題更多的是術語。 – rgin

回答

7

它被稱爲Short-circuit evaluation

短路表達x Sand y(使用砂來表示短路品種)等效於條件表達式if x then y else false;表達x Sor y相當於if x then true else y

+2

這整天都在殺我。謝謝! – rgin