PHP empty()

📔 : PHP 🔗

empty() method check करता है कि क्या कोई variable empty है , empty होने पर true otherwise false return करता है।


यह function isset() से थोड़ा different है , isset() जहाँ ये check करता था कि कि कोई variable किसी value के साथ declare किया गया है या नहीं। वही दूसरी तरफ empty() यह check करता है की define किया गया variable empty तो नहीं है।

यहाँ empty का मतलब है कि variable को empty string / null / empty Array / false / 0 assign किया गया है।

PHP empty Syntax

empty ( mixed $var );

  1. mixed $var | required : variable जिसे आपको check करना है। 

    Understanding mixed Type

    mixed type का मतलब होता है , कि आप अपनी need के according किसी भी type (String , Boolean , Array , Class , Numeric) की value pass कर सकते हैं। यह जरूरी नहीं है कि कोई special type की value ही pass करें।

  2. Return Value : अगर variable empty है , तो true return होता है और बाकी conditions में false return होता है।


PHP empty Example

File : php_empty.php

Copy Fullscreen Close Fullscreen
<?php 
/*these all values are empty*/
$testCase = array(
    1 => '',
    2 => "",
    3 => null,
    4 => array(),
    5 => FALSE,
    6 => NULL,
    7=>'0',
    8=>0,
   
);
foreach ($testCase as $k => $v) {
    if (empty($v))
        echo "<br> $k=>$v is empty";
}
?>
Output
1=> is empty
2=> is empty
3=> is empty
4=>Array is empty
5=> is empty
6=> is empty
7=>0 is empty
8=>0 is empty

Related Topics :

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