2013-07-10 31 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