2
$array = ['name'=>'Jonh', 'lastname' => 'Doe', 'nickname' => 'JD'] ;

$person = $array['name'] ?? null ; //try to change  null to true or false<br>
    echo $person;

$person = $array['age'] ?? null;  //no Undefined index: age<br>
    echo $person;

I can't find any documentation about it.

Mehul Kuriya
  • 608
  • 5
  • 18
Adhikhom
  • 37
  • 2

3 Answers3

8

It's new PHP7 "null coalescing operator":

// 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';

While

short form of Ternary Operator ?: does nearly the same for years (as of at least PHP 5.3)

vladkras
  • 16,483
  • 4
  • 45
  • 55
2

You can find doc about it in php.net here.

EDIT:

It works like combination of isset() and ? So code like:

return isset($a)?$a:$b

could be something like:

return $a??$b
2

This is a null coalescing operator- Please refer to this link

vladkras
  • 16,483
  • 4
  • 45
  • 55
Ltaylor
  • 85
  • 8