I have (or not) a variable $_GET[\'myvar\'] coming from my query string and I want to check if this variable exists and also if the value corresponds to somethi
$_GET[\'myvar\']
As of PHP7 you can use the Null Coalescing Operator ?? to avoid the double reference:
??
$_GET['myvar'] = 'hello'; if (($_GET['myvar'] ?? '') == 'hello') { echo "hello!"; }
Output:
hello!
In general, the expression
$a ?? $b
is equivalent to
isset($a) ? $a : $b