+ 3
Warning about Shorthand Form of the Ternary Operator
Ternary Operator ( expression1 ) ? expression2 : expression3; Has Obvious output but be carefull of the Shorthand Form of the Ternary Operator (From PHP 5.3 onwards, you can omit the second expression in the list) ( expression1 ) ?: expression3; This code evaluates to the VALUE OF expression1 if expression1 is true; otherwise it evaluates to the value of expression3. See Example: https://code.sololearn.com/wUcpXw0i2iPM
2 Answers
+ 9
thanks for your warning.
+ 9
C# has another:
object1 ?? object2;
if object1 is null then object2 will be returned instead of object1. It works like this.
if(object1 != null)
return object1;
else
return object2;