PHP Null Coalescing Operator In Hindi , Null Coalescing Operator kya hai ?

Blogs ❯❯ PHP

Image could not load

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 होगा।

Null Coalescing Operator Example

<?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 के बारे अच्छे से समझ गए होंगे।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook