PHP: empty() function


The empty() function is used to check whether a variable is empty or not. Often, you may encounter a scenario, when you need to code in fashion if a variable is empty or another thing if it is not so. In these situations, empty function comes to rescue.


(PHP 4 and above)




Name Description Required /
var_name The variable being checked. Required Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value:

FALSE if var_name has a non-empty and non-zero value.

Value Type: Boolean

List of empty things :

  • "0" (0 as a string)
  • 0 (0 as an integer)
  • "" (an empty string)
  • NULL
  • "" (an empty string)
  • array() (an empty array)
  • $var_name; (a variable declared but without a value in a class)

Example :

$istr1='Learning empty';
if (empty($ivar1))
echo '$ivar1'." is empty or 0. <br />";
echo '$ivar1'." is not empty or 0. <br />";
if (empty($istr1))
echo '$istr1'." is empty or 0. <br />";
echo '$istr1' ." string is not empty or 0. <br />";


$ivar1 is empty or 0.
$istr1 string is not empty or 0. 

View the example in the browser

Practice here online :

See also

PHP Function Reference

Previous: debug_zval_dump
Next: floatval

PHP: Tips of the Day

PHP - Cannot simply use PostgreSQL table name ("relation does not exist")

From what I've read, this error means that you're not referencing the table name correctly. One common reason is that the table is defined with a mixed-case spelling, and you're trying to query it with all lower-case.

In other words, the following fails:

CREATE TABLE "SF_Bands" ( ... );

SELECT * FROM sf_bands;  -- ERROR!

Use double-quotes to delimit identifiers so you can use the specific mixed-case spelling as the table is defined.


Re your comment, you can add a schema to the "search_path" so that when you reference a table name without qualifying its schema, the query will match that table name by checked each schema in order. Just like PATH in the shell or include_path in PHP, etc. You can check your current schema search path:

SHOW search_path

You can change your schema search path:

SET search_path TO showfinder,public;

Ref : https://bit.ly/3sD9AeC