I've always used this code to run one line if statements.

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

Basically it would run the function if $variable is TRUE.

My question: What is the correct term for doing it this way?

有帮助吗?

解决方案

It is called Short-circuit evaluation.

The short-circuit expression x Sand y (using Sand to denote the short-circuit variety) is equivalent to the conditional expression if x then y else false; the expression x Sor y is equivalent to if x then true else y.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top