Hello Friends,
Today we will discuss about PHP 7 another new feature which is The null coalesce operator. This operator denoted by ?? (double question mark) and it replace the ternary operator feature in a single line with less code than ternary operator.
Following the example with ternary operator:
<?php
$name = isset($_GET['name']) ? $_GET['name'] : 'Not Found';
var_dump($name);
?>
Now Php 7 makes this code simple with less code than ternary operator, following the example with null coalesce operator:
<?php
$name = $_GET['name'] ?? 'Not Found';
var_dump($name);
?>
Above example will refer same result as example first example with very less coding.
Note* : The null coalesce operator is denoted by ??
Thanks,
Vipul Srivastava
0 Comment(s)