PHP's boolean operators always return a boolean value... as opposed
to other languages that return the value of the last evaluated
expression.
For example:
$a = 0 || 'avacado';
print "A: $a\n";
will print:
A: 1
in PHP -- as opposed to printing "A: avacado" as it would in a language like Perl or JavaScript.
This means you can't use the '||' operator to set a default value:
$a = $fruit || 'apple';
instead, you have to use the '?:' ternary operator:
$a = ($fruit ? $fruit : 'apple');
if you're using PHP 7+ then you can user null-coalescing operator ??: too.
<?php
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
// Coalescing can be chained: this will return the first
// defined value out of $_GET['user'], $_POST['user'], and
// 'nobody'.
$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';
?>
For more information, you can refer to this link.
For null coalescing operator use this
link
.