WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML


 

PHP 7 Null Coalescing Operator


In PHP 7, another component, null Coalescing Operator (??) has been presented. It is utilized to supplant the ternary activity related to isset() work. The Null combining Operator restores its first operand on the off chance that it exists and isn't NULL; else it restores its second operand.

Example

<?php
   // fetch the value of $_GET['password'] and returns 'not go'
   // if password is not go
   $password = $_GET['password'] ?? 'not go';
   print($password);
   print("
"); // Equivalent code using ternary operator $password = isset($_GET['password']) ? $_GET['password'] : 'not go'; print($password); print("
"); // Chaining ?? operation $password = $_GET['password'] ?? $_POST['password'] ?? 'not go'; print($password); ?>

It produces the following browser output −

Result :


not go
not go
not go