Isn't the output null (null? Isn't the output null (null?
Reply content:
Isn't the output null (null?
It is a simple way to write a ternary operator. 5 is output if it is true.
This document provides an explanation for the ternary operators.
Expression (expr1 )? (Expr2): (expr3) when the value of expr1 is TRUE, the value is expr2, and when the value of expr1 is FALSE, the value is expr3.
From PHP 5.3, the portion in the middle of the ternary operator can be omitted. Expression expr1? : Expr3 returns expr1 when the value of expr1 is TRUE; otherwise, expr3 is returned.
If the value of 5 is greater than 0, true is returned. If the php ternary expression ignores the second parameter and the result is true, the first parameter is returned.
A? A: B; // can be abbreviated as? : B; // so the above sentence is equivalent to echo 5? 5: 1;
A? : B;, if expression a is the expression, the expression will not be executed again, and? A: B; if the expression returns true, It will be executed again.
Because 5 is true.