PHP isset() vs empty() vs is_null()

This php tutorial help to understand difference between PHP isset() vs empty() vs is_null().These method are used to test the value of a variable.You can use isset(), empty() and is_null() for test variable have a value or not.

Normally, We have used these functions into the php application.All these functions return a Boolean value.In this post I will explain the differences between these functions.

PHP isset() Example

This isset() method used to determine if a variable is set and is not NULL.You can read isset() manual.

it returns TRUE only when the variable is not null.

Output:

PHP empty() Example

This empty() method used to determine if a variable is set and not empty.You can read empty() manual.

it returns True if var is empty string, false, array(), NULL, 0, and an unset variable. Otherwise returns False.

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)

PHP empty() example

Output :

PHP is_null() Method

The is_null() method use to determine finds whether a variable is NULL or not.You can read empty() manual.

It returns TRUE if var is null, FALSE otherwise.

is_null Example

Output :
bool(true)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.