It's the "null coalescing operator", added in php 7.0. The definition of how it works is:
It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.
So it's actually just isset() in a handy operator.
Those two are equivalent1:
bar ?? 'something';
$foo = isset(
bar : 'something';
Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
And original RFC https://wiki.php.net/rfc/isset_ternary
EDIT: As this answer gets a lot of views, little clarification:
1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.
It's the "null coalescing operator", added in php 7.0. The definition of how it works is:
It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.
So it's actually just isset() in a handy operator.
Those two are equivalent1:
bar ?? 'something';
$foo = isset(
bar : 'something';
Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
And original RFC https://wiki.php.net/rfc/isset_ternary
EDIT: As this answer gets a lot of views, little clarification:
1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.
$myVar = $someVar ?? 42;
Is equivalent to :
$myVar = isset($someVar) ? $someVar : 42;
For constants, the behaviour is the same when using a constant that already exists :
define("FOO", "bar");
define("BAR", null);
$MyVar = FOO ?? "42";
$MyVar2 = BAR ?? "42";
echo $MyVar . PHP_EOL; // bar
echo $MyVar2 . PHP_EOL; // 42
However, for constants that don't exist, this is different :
$MyVar3 = IDONTEXIST ?? "42"; // Raises a warning
echo $MyVar3 . PHP_EOL; // IDONTEXIST
Warning: Use of undefined constant IDONTEXIST - assumed 'IDONTEXIST' (this will throw an Error in a future version of PHP)
Php will convert the non-existing constant to a string.
You can use constant("ConstantName") that returns the value of the constant or null if the constant doesn't exist, but it will still raise a warning. You can prepended the function with the error control operator @ to ignore the warning message :
$myVar = @constant("IDONTEXIST") ?? "42"; // No warning displayed anymore
echo $myVar . PHP_EOL; // 42
Understanding the Use of the "..." Operator in PHP
What is the difference between ' ' and " " in PHP ? and when, where should I use it
?: operator (the 'Elvis operator') in PHP - Stack Overflow
php equivalent of mysql "IN" operator? - Stack Overflow
Videos
I recently came across a PHP code snippet that uses the "..." operator in a context that I'm not very familiar with. The code includes a method called initials that uses the "..." operator in an array_map function. Here's the code snippet for reference:
class HighSchoolSweetheart
{
public function initial(string $name): string
{
return strtoupper($this->firstLetter($name)) . '.';
}
public function initials(string $name): string
{
$initials = array_map($this->initial(...), explode(' ', $name));
return implode(' ', $initials);
}
}I understand that the "..." operator is often used for argument unpacking in PHP and that array_map is used to apply a callback function ($this->initial(...)) to each element of an array created by explode(' ', $name). However, I'm not entirely clear on how the splat operator "..." functions in this context. Can someone explain its role in this code and how it affects the initial method? Thanks!
It evaluates to the left operand if the left operand is truthy, and the right operand otherwise.
In pseudocode,
foo = bar ?: baz;
roughly resolves to
foo = bar ? bar : baz;
or
if (bar) {
foo = bar;
} else {
foo = baz;
}
with the difference that bar will only be evaluated once.
You can also use this to do a "self-check" of foo as demonstrated in the code example you posted:
foo = foo ?: bar;
This will assign bar to foo if foo is null or falsey, else it will leave foo unchanged.
Some more examples:
<?php
var_dump(5 ?: 0); // 5
var_dump(false ?: 0); // 0
var_dump(null ?: 'foo'); // 'foo'
var_dump(true ?: 123); // true
var_dump('rock' ?: 'roll'); // 'rock'
var_dump('' ?: 'roll'); // 'roll'
var_dump('0' ?: 'roll'); // 'roll'
var_dump('42' ?: 'roll'); // '42'
?>
By the way, it's called the Elvis operator.

See the docs:
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression
expr1 ?: expr3returnsexpr1ifexpr1evaluates toTRUE, andexpr3otherwise.
http://php.net/manual/en/function.in-array.php
However, it's worth noting that you're sort of conflating two types of languages; PHP is a scripting language, SQL is a query language. They serve two very different purposes and do very different things behind the scenes, so it's an important distinction.
[edit: Without using an array? Probably not, no; you're throwing out the construct that is specifically useful in this instance]
The answer is to use in_array(), but if you use it a lot, make an alias:
use function in_array as in;
if (in(a,
foo, $bar]) {
}