PHP empty() function – Check variable is empty or not

PHP empty() Function

The empty() function is used to check whether a variable empty or not.

empty  function syntax

empty(“variable”);

The empty() function returns true or false value.

  • True – If variable has empty or zero(0) value.
  • False – If variable has non-empty and non-zero value.

Example of empty() function

Here, declare two variable one with empty  string value and another with some text value and check variable whether is empty or not using php empty() function.

The output is empty() function :

The str1 is empty or 0
The str2 is not empty


PHP  empty() function example

Here, we design a php form with a textbox and a button control. here we check whether the textbox values is empty or not. If textbox value is empty then display error message “Enter text”, and if textbox has some value then return a success message on php form.

The output is :

PHP empty() function example

PHP empty() function example

 

 

Leave a Reply

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

9 + 2 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">