+ 6
$var=true?1:false?2:3; ??
Hi, i found something like this while doing challenges. Can anyone explain how i do this calculation and what the name of it is?
4 Antworten
+ 5
This is using the ternary operator 😉 its like a shorthand way to using if and else statements your result would be 1 as the first condition is true if it was false you would get 3 as your conditional statement before last returned false.
Your example behind the scene looks like this
condition ? exprTrue : exprFalse?exprTrue:exprFalse;
+ 3
Thank's for the answers 😄
+ 2
https://www.sololearn.com/learn/Swift/2338/
See ternary operator example here
+ 1
This is called Ternary Expression.
(Ternary Operator : An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c)
$var=true?1:false?2:3;
$var=True?1:false; // first this expression evaluated
Then $var=1;
$var=1?2:3; // second this expression evaluated
Then $var=2;
https://code.sololearn.com/wBv0RrjcQGVO/#php