Loading ...
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Image on pixabay
PHP में Null Coalescing Operator सिर्फ ternary operator की जगह use किया जाने वाला operator था। जिसका main purpose isset() और ternary operator को replace की तरह use में लिया गया। इस Operator को PHP version 7
में introduce किया था।
Null coalescing operator , दो operands के साथ work करता है अगर first operand की value null
, empty और undefined
नहीं हुआ तो first operand return करेगा otherwise second operand return होगा।
<?php
// here $var is not defined.
echo $var ?? "Variable not defined";
?>
इसी तरह से अगर variable की value null
या 0 हुई तो second operand return होगा।
<?php
$var = null;
echo $var ?? "null Variable";
echo "<br/>"; // line break.
// now put some value.
$var = "Hello ! learners.";
echo $var ?? "null Variable";
?>
Null coalescing operator काफी easy to use है और ternary या if-else के comparison में काफी short भी है। इसे आप one line code वाली condition की जगह आसानी से use कर सकते हैं।
अब आप PHP में Null coalescing operator के बारे अच्छे से समझ गए होंगे।
4.
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook