Why to check both isset() and !empty() function in PHP ?- Tutorialpath

Welcome to all our readers on our website at www.tutorialpath.com. As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world. As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating php isset() and !empty() functions. With the help of this article you will get to know the complete process of how to create php isset() and !empty() functions in a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.

Why to check both isset() and !empty() function in PHP ?

Php provides some magical predefined functions to handle variables in real-time applications. In this article we will study about the isset() and !empty() functions and implement both these functions with some examples.


The isset() function is an inbuilt function in PHP. The isset() function is check whether a variable is declared in the application is set or not. This function restores the outcome as true or false.


bool isset( $var, mixed )


This function accepts more than one parameter. The first parameter of this function is $ var. This parameter is used to store the value of a variable.



// PHP program to illustrate
// isset() function
$one = ‘0’;

if( isset( $num ) ) {
print_r(” $one is set with isset function <br>”);

// Declare an empty array
$array = array();

// Use isset function
echo isset($array[‘geeks’]) ?
‘array is set.’ : ‘the array is not set.’;


0 is set with isset function 
the array is not set.

empty() Function:

The empty () function decides whether a given variable is empty or NULL. The empty () function is the complement of the empty () function. The empty () function is quite similar! The isset () function is equal to and the !empty () function is equal to the isset () function.


   $num1 = 0;
   var_dump(empty($num1)) ;
   var_dump(!empty($num1)) ;




Here var1 =0 ,when we perform empty() function over this,it will evaluate as TRUE because 0 is considered as empty.

Example 1:-


// PHP program to illustrate
// empty() function

$temp = 0;

// It returns true because
// $temp is empty
if (empty($temp)) {
echo $temp . ‘ it is considered empty’;

echo “\n”;

// It returns true since $new exist
$new =1 1;
if (!empty($new)) {
echo $new . ‘ it is considered set’;


0 it is considered empty
11 it is considered set


The following values are considered to be empty:

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


So, hopefully we have shared all the basic steps that help you php isset() and !empty() functions.  PHP extract the last character from a string. In this tutorial, you have several ways for PHP to remove the last character from any given strings.


Leave a Reply

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