• PHP Video Tutorials

PHP - isset() Function


Advertisements

Definition and Usage

The function isset() is used to determine is a variable is set/declared and is not null.

If a variable has been unset with the unset() function, it is no longer considered to be set.

Syntax

bool isset ( mixed $var , mixed ...$vars )

Parameters

Sr.No Parameter & Description
1

var

Mandatory. The variable to be checked.

2

vars

Optional. Further variables.

Return Values

This function returns true if var exists and has any value other than null. false otherwise.

This function will return false when checking a variable that has been assigned to null. A null character ("\0") is not equivalent to the PHP null constant.

If multiple parameters are supplied then isset() will return true only if all of the parameters are considered set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of function isset() −

<?php
   $a = "";
   echo "a is ".( isset($a)? 'set' : 'not set') . "<br>";

   $b = "test";
   echo "b is ".( isset($b)? 'set' : 'not set') . "<br>";

   $c = "test2";
   echo "checking b and c are ".( isset($b,$c)? 'set' : 'not set') . "<br>";

   echo "****after unset b**** <br>";
   unset ($b);
   echo "b is ".( isset($b)? 'set' : 'not set') . "<br>";
   echo "checking b and c are ".( isset($b,$c)? 'set' : 'not set') . "<br>";

   $d = 1;
   echo "d is ".( isset($d)? 'set' : 'not set') . "<br>";

   $e = NULL;
   echo "e is ".( isset($e)? 'set' : 'not set') . "<br>";

   $f = array('a' => 'apple');
   echo "f is ".( isset($f)? 'set' : 'not set') . "<br>";

   $g = new stdClass();
   echo "g is ".( isset($g)? 'set' : 'not set') . "<br>";

   $h = '';
   echo "h is ".( isset($h)? 'set' : 'not set') . "<br>";
?>

Output

This will produce following result −

a is set
b is set
checking b and c are set
****after unset b****
b is not set
checking b and c are not set
d is set
e is not set
f is set
g is set
h is set
php_variable_handling_functions.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements