Difference among isset, is_null and empty in PHP

Author - Parminder Kaur

Difference among isset, is_null and empty in PHP

Php has different methods to check the value of the variable. The methods isset(), empty() and is_null() are very useful methods and all returns a boolean value. Let see the difference between these methods for different variable values.

1. isset():- ISSET in Php determines if the variable is set and not null. It means if a variable is assigned any value (even empty string except null) then it will return TRUE. It is not set if it is declared null or just the declaration of variable without any value e.g. var $user; .

Isset also works on unknown variables which are not declared.

Eg. a variable with values ”0”,”1”,TRUE, 0,FALSE,”abc”, “ ” is considered TRUE for ISSET.

2. empty():- EMPTY in Php determines if a variable is empty. It will return TRUE only if a variable is false, an empty string, empty array(), NULL, 0 or an unset variable.

3. is_null():- IS_NULL in Php determines if a variable contain null value. It will return TRUE only if variable is equal to null. It is opposite of isset() except it works only on declared variables and not on unknown variables.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *