Isset in PHP

PHP Isset(), Unset() Functions

Isset in PHP The isset() function check whether a variable is set or not.

ISSET return TRUE if the variable exists or set and contains the value other than NULL. Here the variable can be “”, 0, “0” or FALSE therefore this variable return TRUE for ISSET.

Result/Return Value : This function will return Boolean value ‘True’ if the variable exists and ‘False’ if the variable doesn’t exists or has a value equal to Null and if multiple variables have been used, they must be set or have existence in order to return True but if they all are not set, it will return False.

Errors : Pass only the variables in the Isset() function and if parameters other than variables are passed in isset function. After that, it will show a Parse Error.

Isset in PHP

Example 1

<?php
$var = "test";   //string
if(isset($var)){
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

inside the isset function

Example 2

<?php
$var = "";      //empty string
if(isset($var)){
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

inside the isset function

Example 3

<?php
$var = 0;       //integer
if(isset($var)){
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

inside the isset function

Example 4

<?php
$var = false;
if(isset($var)){
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

inside the isset function

Isset in PHP ISSET return false if variable is not set or contains a NULL value.

Example 1

<?php
$var = null;     // Here $var has null value
if(isset($var)){
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

isset function not work

Example 2

<?php
if(isset($var)){   // Here $var is not set
 echo "inside the isset function";
}
else{
 echo "isset function not work";
}
?>

Output

isset function not work

PHP Empty Function

The empty() function check whether a variable is empty.

Empty is treated as “” (empty string), 0 (integer), “0” (string), 0.0 (float), FALSE, NULL and array() (empty array).

Example 1

<?php
$var = "";
if(empty($var)){
 echo "inside the empty function";
}
else{
 echo "outside from empty function";
}
?>

Output

inside the empty function

Example 2

<?php
$var = false;
if(empty($var)){
 echo "inside the empty function";
}
else{
 echo "outside from empty function";
}
?>

Output

inside the empty function

Unset Function in PHP

The unset() function is an inbuilt function in PHP and is used to destroys a given variable or unset a specified variable.

Result/Return Value : It returns no value, i.e. void

Errors : Pass only the variables in the unset() function and if parameters other than variables are passed in unset function. After that, it will show a Parse Error.

Example

<?php
$website='developerhelps.com';
echo '<br>Before using unset() the value of $website is : '. $website;
unset($website);
echo 'After using unset() the value of $website is : '. $website;
?>

Output

Before using unset() the value of $website is : developerhelps.com
Notice: Undefined variable: website 
After using unset() the value of $website is :

More Related Post

Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

Leave a comment

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

0 0 0
FOLLOW ON