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?
PHP Conditional Statements if statement - executes some code if one condition is true. if...else statement - executes some code if a condition is true and another code if that condition is false. if... elseif...else statement - executes different codes for more than two conditions.
<? php if (argument) { // end if statement } else if (different argument) { // end if statement } else if (another different argument) { // end if statement } else { // do something } ?>
The nested if statement contains the if block inside another if block. The inner if statement executes only when specified condition in outer if statement is true.
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 expressionif x then y else false;
the expressionx Sor y
is equivalent toif x then true else y
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With