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 and this variable return TRUE for ISSET.

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, 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 which is used to destroys a given variable or unset a specified variable.

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