note 125280 deleted from language.operators.comparison by crell

From: Date: Thu, 31 Mar 2022 17:28:34 +0000
Subject: note 125280 deleted from language.operators.comparison by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217863@lists.php.net to get a copy of this message
Note Submitter: halfhearted13 at gmail dot com ---- Both Null Coalescing ( ?? ) and Ternary ( ? : ) can work at a time. <?php $a = "user name"; echo $a = null ?? $a ? "sb" : "not found"; // it prints : sb //as null coalescing has null on left it goes to 2nd expr $a. $a is defined so //output will be the 1st expr of Ternay operator. ?> <?php echo $x = "" ?? "" ? : "not found"; // it prints: not found. // null coalescing has empty value of its left. so it prints right expr which is //also empty. so the output will be the 2nd expr of ternary(written in short) ?> <?php echo $x = "" ?? "" ?? "" ? : false; // prints nothing. // if you add var_dump() you see bool(false) ?>

« previous php.notes (#217863) next »