Difference among isset, is_null and empty in PHP

|
| By Webner

Learn to Differentiate 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.

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.

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.

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.

Leave a Reply

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