I like to do this in JavaScript:
function (a, b, c) {
var foo = a || b || c;
return foo.bar;
}
Is there a quick way to do assignment with fallback or does it require a custom function
?
I like to do this in JavaScript:
function (a, b, c) {
var foo = a || b || c;
return foo.bar;
}
Is there a quick way to do assignment with fallback or does it require a custom function
?
1 Answer
Reset to default 21PHP 5.3 introduces the ?:
operator (not to be confused with the ternary conditional, go figure). I don't use PHP, but I imagine it'd be something like:
$foo = $a ?: $b ?: $c
See: http://php/manual/en/language.operators.parison.php
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.
Happy coding.