PHP empty() Function

PHP empty() Function

The empty() function in PHP determines whether the specified variable is empty or not. The specified variable is considered empty if it does not exist or if its value is equal to FALSE. This function does not generate a warning if the variable does not exist.

Syntax

Parameter

var(required)– This parameter represents the variable that is to be checked.

Return

This function returns a Boolean value FALSE if the ‘var’ parameter exists and has a non-empty, non-zero value else it returns TRUE.

The empty values are as follows:

  • “” (an empty string)
  • 0 (0 as an integer)
  • (0 as a float)
  • “0” (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output