Php isset() method

PHP isset() method is used to check the variable or array or object’s property is exists or not. It gives output in a boolean value. if the variable or array element or object’s property exists then the output will be true or 1 and if the variable or array or object’s property does not exist then the output will be false or 0.

Syntax:- to check the variable


<?php
isset($variable_name)
?>

Example:- Suppose, You have employee_name variable which has value John and now you want to check employee_name variable is exists or not.


<?php
$employee_name="John";
if(isset($employee_name))
{
echo $employee_name.' is exists';
}

?>
Output:- John is exists

Try it Yourself

Example2:- Suppose, You check employee_age exists or not


<?php
if(isset($employee_age))
{
echo $employee_age.' is exists';

}else{

echo 'employee age does not exist';

}

?>
Output:- employee age does not exist

Try it Yourself

Php isset() method – Interview Questions

Q 1: What is isset() in PHP?

Ans: It checks whether a variable is set and not NULL.

Q 2: What does isset() return?

Ans: It returns true or false.

Q 3: Can isset() check multiple variables?

Ans: Yes.

Q 4: Is isset() faster than empty()?

Ans: Yes, generally faster.

Q 5: Is isset() used with arrays?

Ans: Yes, commonly to check array keys.

Php isset() method – Objective Questions (MCQs)

Q1. isset() is used to check whether a variable is ______.






Q2. What is the return type of isset()?






Q3. Which of the following returns true?

$var = 5; isset($var);






Q4. isset() can check multiple variables at once?






Q5. isset($var) returns false if variable is ______.






Related Php isset() method Topics