Code: Select all
::$r = ("a" == "a"); $r = ($r?"True":"False"); msg $r;
how to interpret ($r?"true":"False")?
Is the "?" (question mark) an implied "if"?
Code: Select all
::$r = ("a" == "a"); $r = ($r?"True":"False"); msg $r;
Code: Select all
$r = ("a" == "a");
Code: Select all
$r = ($r?"True":"False");
Yes, I found it in the manual. I should have read ahead to locate the description on the weird construct (condition)? value-if-true : value-if-false.highend wrote:It's a ternary conditional.
Thank you for your reminder. Agree. I'll follow your scripting style because it helps improve readability.SammaySarkar wrote:in my opinion, it's a good idea to enclose the whole thing in another set of braces: ( (condition) ? ReturnIfTrue : ReturnIfFalse )
Code: Select all
// nested ternaries
//$coolVar = "cool";
//$groofyVar = "groof";
echo (isset($groofyVar)?$groofyVar:(isset($coolVar)?$coolVar:"NO"));