Update 14/08/24 · Read 1 minute
?:is like a gate that letsanything falsythrough – includingNULL- Anything falsy:
0,empty string,NULL,false,!isset(),empty() - Same like old ternary operator:
X ? Y : Z - Note:
?:will throwPHP NOTICEon undefined (unsetor!isset()) variables
Use of ?:
- checking
empty(),!isset(),is_null()etc - shorten ternary operation like
!empty($x) ? $x : $yto echo$x ?: $y - shorten
if(!$x) { echo $x; } else { echo $y; }to echo$x ?: $y