tenerarry operator php code example
Example 1: php ternary operator
<?php
(if Condition) ? (stat1) : (stat2);
$var1 = 5;
$var2 = 2;
echo $check = ($var1 > $var2) ? "right" : "wrong";
?>
Example 2: php ?? vs ?:
<?php
var_dump(null ?? '`null` is null');
var_dump(null ?: '`null` is empty');
var_dump(true ?? '`true` is null');
var_dump(true ?: '`true` is empty');
var_dump(false ?? '`false` is null');
var_dump(false ?: '`false` is empty');
var_dump('' ?? 'empty string is null');
var_dump('' ?: 'empty string is empty');
var_dump(empty(null) ?: '`null` is not empty');