Looking at a script PHP at some point I came across this line
$valor = $_GET['id'] ?? 1;
What is the interpretation of this code? What does it do?
Looking at a script PHP at some point I came across this line
$valor = $_GET['id'] ?? 1;
What is the interpretation of this code? What does it do?
??
is known as null coalescing was added in the PHP 7 . Its functionality is to return the first operand if it exists and is not null otherwise the second returns.
The code in PHP 7
$valor = $_GET['id'] ?? 1;
Can be translated into PHP 5 as
$valor = isset($_GET['id']) ? $_GET['id'] : 1;
Related:
What does the "?" operator mean in PHP?
What not to do : Is it possible to use the ternary operator in several conditions simultaneously?
Same as in C # and other languages, this is #
$valor = isset($_GET['id']) ? $_GET['id'] : 1;