Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top